Skip to content

Instantly share code, notes, and snippets.

@JosephRedfern
Created January 28, 2013 15:35
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 JosephRedfern/4656509 to your computer and use it in GitHub Desktop.
Save JosephRedfern/4656509 to your computer and use it in GitHub Desktop.
Nginx Site Aded
#!/bin/bash
#path to folder containing folders referenced by nginx server blocks
SERVERPATH="/var/www"
#name of logs folder
LOGFOLDER="logs"
#name of www folder (i.e. folder where web files are held)
WWWFOLDER="public_html"
#name of nginx sites folder
NGINXFOLDER="/etc/nginx/sites-enabled"
#END CONFIGUARABLES
set -e
echo "nginx server block creator"
echo -n "creating $SERVERPATH/$1/..."
mkdir "$SERVERPATH/$1"
echo "Done!"
echo -n "creating $SERVERPATH/$1/$LOGFOLDER..."
mkdir "$SERVERPATH/$1/$LOGFOLDER"
echo "Done!"
echo -n "creating $SERVERPATH/$1/$WWWFOLDER..."
mkdir "$SERVERPATH/$1/$WWWFOLDER"
echo "Done!"
touch $NGINXFOLDER/$1
CONFIG="server {
server_name www.$1 $1\;
access_log $SERVERPATH/$1/$LOGFOLDER/access.log\;
error_log $SERVERPATH/$1/$LOGFOLDER/error.log\;
root $SERVERPATH/$1/$WWWFOLDER\;
location / {
index index.html index.htm index.php\;
}
autoindex on\;
include enable_php\;
}
"
echo $CONFIG > $NGINXFOLDER/$1
/etc/init.d/nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment