Created
September 27, 2013 15:40
-
-
Save dansku/6730634 to your computer and use it in GitHub Desktop.
Add new domain to nginx, then you need to restart nginx!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| import os | |
| print "Create New Domain!" | |
| dom = raw_input("DomainName: ") | |
| print "Creating domain", dom | |
| print "Creating folder /var/www/" + dom + '/html' | |
| os.system("mkdir /var/www/" + dom) | |
| os.system("mkdir /var/www/" + dom + '/html') | |
| os.system("chown -R www-data:www-data /var/www/" + dom ) | |
| print "Creating site-available" | |
| fileName = dom | |
| os.system("echo 'server {' >> " + fileName) | |
| os.system("echo ' listen 80;' >> " + fileName) | |
| os.system("echo ' server_name www."+dom+";' >> " + fileName) | |
| os.system("echo ' return 302 http://"+dom+"$request_uri;' >> " + fileName) | |
| os.system("echo '}' >> " + fileName) | |
| os.system("echo 'server {' >> " + fileName) | |
| os.system("echo ' root /var/www/"+dom+"/html;' >> " + fileName) | |
| os.system("echo ' index index.html index.php index.htm;' >> " + fileName) | |
| os.system("echo ' server_name "+dom+";' >> " + fileName) | |
| os.system("echo ' location / {' >> " + fileName) | |
| os.system("echo ' try_files $uri $uri/ /index.php?q=$uri&$args;' >> " + fileName) | |
| os.system("echo ' }' >> " + fileName) | |
| os.system("echo ' error_page 404 /404.html;' >> " + fileName) | |
| os.system("echo ' error_page 500 502 503 504 /50x.html;' >> " + fileName) | |
| os.system("echo ' location = /50x.html {' >> " + fileName) | |
| os.system("echo ' root /usr/share/nginx/www;' >> " + fileName) | |
| os.system("echo ' }' >> " + fileName) | |
| os.system("echo ' location ~ \.php$ {' >> " + fileName) | |
| os.system("echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> " + fileName) | |
| os.system("echo ' fastcgi_index index.php;' >> " + fileName) | |
| os.system("echo ' include fastcgi_params;' >> " + fileName) | |
| os.system("echo ' }' >> " + fileName) | |
| os.system("echo '}' >> " + fileName) | |
| print 'Moving to site-available' | |
| os.system("mv " + dom + " /etc/nginx/sites-available/") | |
| print 'Link' | |
| os.system("sudo ln -s /etc/nginx/sites-available/"+dom+" /etc/nginx/sites-enabled/"+dom) | |
| print 'DONE!' |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know it would be much better to make a bash script, but it's ok! :)