PHP Classes

File: python_create_nginx_vhost.py

Recommend this page to a friend!
  Classes of ask sa sa   PHP Artificial Intelligence Example Code Generated by OpenAI   python_create_nginx_vhost.py   Download  
File: python_create_nginx_vhost.py
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: PHP Artificial Intelligence Example Code Generated by OpenAI
OpenAI-generated code in PHP and other languages
Author: By
Last change:
Date: 1 year ago
Size: 773 bytes
 

Contents

Class file image Download
import subprocess def create_vhost(server_name, root_directory): # Create the configuration file for the vhost config_file = f""" server {{ listen 80; server_name {server_name}; root {root_directory}; index index.html; }} """ # Write the configuration file to /etc/nginx/sites-available with open(f"/etc/nginx/sites-available/{server_name}", "w") as f: f.write(config_file) # Create a symbolic link from the configuration file to the sites-enabled directory subprocess.run(["ln", "-s", f"/etc/nginx/sites-available/{server_name}", "/etc/nginx/sites-enabled/"]) # Reload nginx to apply the changes subprocess.run(["nginx", "-s", "reload"]) # Example usage: create_vhost("example.com", "/var/www/example.com")