Skip to content

Instantly share code, notes, and snippets.

@SpellCraft

SpellCraft/make_vhost.php Secret

Created Dec 6, 2016
Embed
What would you like to do?
#!/usr/bin/php
<?php
$block = "server {
listen 80;
root /usr/share/nginx/html/{$argv[1]};
index index.php index.html index.htm;
server_name {$argv[1]};
location / {
try_files \$uri \$uri/ =404;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
try_files \$uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}";
mkdir("/usr/share/nginx/html/{$argv[1]}");
touch("/usr/share/nginx/html/{$argv[1]}/index.html");
file_put_contents("/etc/nginx/sites-available/{$argv[1]}", $block);
symlink("/etc/nginx/sites-available/{$argv[1]}", "/etc/nginx/sites-enabled/{$argv[1]}");
system('sudo service nginx reload');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment