Skip to content

Instantly share code, notes, and snippets.

@nicopenaredondo
Created May 11, 2016 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicopenaredondo/351f707d3031d630d6a8b7af9c010aa2 to your computer and use it in GitHub Desktop.
Save nicopenaredondo/351f707d3031d630d6a8b7af9c010aa2 to your computer and use it in GitHub Desktop.
NGINX Subdomain generator
#!/usr/bin/env bash
if [ -z $1 ]
then
echo "serve www.domain.com /path"
exit 1
fi
if [ -z $2 ]
then
echo "serve www.domain.com /path"
exit 1
fi
string="$1"
#var=${string:4:100}
var="$1"
index="index.php"
block="server {
listen 80;
server_name $1;
root $2;
index index.html index.htm $index;
charset utf-8;
location / {
try_files \$uri \$uri/ /$index?\$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /usr/local/etc/nginx/logs/$var-error.log error;
error_page 404 /index.php;
sendfile on;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME \$request_filename;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
}
location ~ /\.ht {
deny all;
}
}"
echo "$block" >> "/usr/local/etc/nginx/sites-available/$var.conf"
ln -s "/usr/local/etc/nginx/sites-available/$var.conf" "/usr/local/etc/nginx/sites-enabled"
sudo nginx -s reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment