Skip to content

Instantly share code, notes, and snippets.

@rnelson
Created February 4, 2014 03:22
Show Gist options
  • Select an option

  • Save rnelson/8797662 to your computer and use it in GitHub Desktop.

Select an option

Save rnelson/8797662 to your computer and use it in GitHub Desktop.
#!/bin/bash
# mksite.sh v0.0.1
# (C) 2014 Ross Nelson
echo "mksite.sh v0.0.1"
echo ""
# Get the name of the domain
while true; do
read -p "Enter domain: " domain
if [ ! -z $domain ]; then
break
fi
done
# Set some variables
export ROOTDIR="/srv/$domain"
export HTDOCSDIR="$ROOTDIR/htdocs"
export LOGSDIR="$ROOTDIR/logs"
export INDEXPAGE="$HTDOCSDIR/index.html"
export TEMPLATEFILE="/etc/nginx/sites-available/TEMPLATE"
export VHOSTFILE="/etc/nginx/sites-available/$domain"
# Make necessary directories in /srv
sudo mkdir -p $HTDOCSDIR
sudo mkdir -p $LOGSDIR
sudo chown -R `whoami`:www-data $HTDOCSDIR
# Add an index page
cat >$INDEXPAGE <<-EOF
<!DOCTYPE html>
<html lang="en">
<head>
<title>$domain</title>
</head>
<body>
<h1>$domain</h1>
<p>Welcome to $domain.</p>
</body>
</html>
EOF
# Create a vhost file
sudo bash -c "sed 's/DOMAIN/$domain/' <$TEMPLATEFILE >$VHOSTFILE"
# Enable the site
(cd /etc/nginx/sites-enabled && sudo ln -s ../sites-available/$domain .)
# Reload nginx's config
sudo /etc/init.d/nginx reload >/dev/null
# Instructions
echo ""
echo "Setup complete."
echo "Place your files in $HTDOCSDIR."
exit 0
server {
listen 80;
server_name www.DOMAIN;
rewrite ^ http://DOMAIN$request_uri?;
}
server {
listen 80;
server_name DOMAIN;
root /srv/DOMAIN/htdocs;
index index.html index.htm index.php;
error_log /srv/DOMAIN/logs/error.log crit;
access_log /srv/DOMAIN/logs/access.log;
location / {
try_files $uri $uri/ =404;
}
location ~ /\.ht {
deny all;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
# Uncomment the following two sections to enable SSL. Be sure to
# set ssl_certificate and ssl_certificate_key to real files
#server {
# listen 443;
# server_name www.DOMAIN;
# rewrite ^ https://DOMAIN$request_uri?;
#}
#server {
# listen 443;
# server_name DOMAIN;
# root /srv/DOMAIN/htdocs;
# root html;
# index index.html index.htm index.php;
#
# ssl on;
# ssl_certificate /srv/DOMAIN/ssl/cert.pem;
# ssl_certificate_key /srv/DOMAIN/ssl/cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv3 TLSv1;
# ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv3:+EXP;
# ssl_prefer_server_ciphers on;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment