Skip to content

Instantly share code, notes, and snippets.

@deanrather
Created July 12, 2012 03:55
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 deanrather/3095621 to your computer and use it in GitHub Desktop.
Save deanrather/3095621 to your computer and use it in GitHub Desktop.
NginX -- Add site to configuration script
#!/bin/bash
#
# usage: sudo configure-website.sh mydomain.com
# Creates the folder to put your site in, creates a nginx config (from a template),
# links it, and restarts nginx
#
# This script makes some assumptions, check / modify before using!!
# - Your websites are stored in /var/www/ and each contain a public/ folder
# - you have a 'template' file in /etc/nginx/sites-available
# - the 'template' file has the key word 'DOMAIN' (which is to be replaced by this script)
echo -e "setting up $1 in nginx"
echo -e "making the folder"
DIRECTORY="/var/www/$1/public"
mkdir -p $DIRECTORY
echo -e "making a test index.php"
echo "$1 is currently under maintenance" > "$DIRECTORY/index.php"
echo -e "creating the config file"
cd /etc/nginx/sites-available/
sed "s/DOMAIN/$1/" <template >$1
echo -e "linking the config file"
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/$1
echo -e "restarting nginx"
service nginx restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment