Skip to content

Instantly share code, notes, and snippets.

@theprivileges
Created May 14, 2013 16:16
Show Gist options
  • Save theprivileges/5577238 to your computer and use it in GitHub Desktop.
Save theprivileges/5577238 to your computer and use it in GitHub Desktop.
A few helper scripts for nginx. One of them creates a site and the other enables that new site.
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $0 USER DOMAIN"
exit 1
fi
if [ -d /var/www/$2 ]; then
echo "$0: site '$2' already exists."
exit 1
fi
mkdir /var/www/$2
chown -R $1:www-data /var/www/$2
mkdir /var/log/nginx/$2
chown -R $1:www-data /var/log/nginx/$2
mkdir -p /home/$1/domains/$2
ln -sf /var/www/$2 /home/$1/domains/$2/www
ln -sf /var/log/nginx/$2 /home/$1/domains/$2/logs
echo "
server {
listen 80; ## listen for ipv4
server_name $2 *.$2;
access_log /var/log/nginx/$2/access.log;
root /var/www/$2;
index index.html index.htm index.php;
#try_files $uri $uri/ /index.php?q=$uri&$args;
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass localhost:9000;
fastcgi_index index.php;
}
}
" > /etc/nginx/sites-available/$2
echo "$0: site '$2' created for user '$1'"
exit 0
#!/bin/sh
if [ $# -ne 1 ]; then
echo "Usage: $0 DOMAIN"
exit 1
fi
if [ -d /etc/nginx/sites-enabled/$1 ]; then
echo "$0: site '$1' already exists."
exit 1
fi
ln -s /etc/nginx/sites-available/$1 /etc/nginx/sites-enabled
/etc/init.d/nginx reload
echo "$0: site '$1' enabled."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment