Skip to content

Instantly share code, notes, and snippets.

@simkimsia
Last active December 20, 2015 08:39
Show Gist options
  • Select an option

  • Save simkimsia/6102024 to your computer and use it in GitHub Desktop.

Select an option

Save simkimsia/6102024 to your computer and use it in GitHub Desktop.
Setup the initial nginx conf file for the very first time. Will point to stage.WEBAPP first
#!/bin/bash
###
#
# Copyright (c) 2013 KimSia Sim
#
# Ubuntu 12.10 based make nginx config files in /etc/nginx/sites-available and /etc/nginx/sites-enabled for
# webapp.com built using cakephp
# Run this by executing the following from a fresh install of Ubuntu 12.10 server:
#
# bash -c "$(curl -fsSL https://raw.github.com/gist/6102024)" <webapp.com> <cakeappfoldername>
#
# Be sure to replace <webapp.com> with your intended webapp name.
# Be sure to replace <cakeappfoldername> with your intended cakephp app foldername
# Also, run this as root, unless you enjoy failing.
#
# Its handy to install 'screen' if you want to ensure your remote connection to
# a server doesn't disrupt the installation process. If you want to do this, just
# do the following before running the main bash command:
#
# apt-get install screen -y
# screen
#
# To recover your session if you are disconnected, ssh to your server as root again,
# and type:
#
# screen -x
#
# Dependencies:
# - curl
#
# Todo:
# - SSL Configuration
#
###
EXPECTEDARGS=1
if [ $# -ne $EXPECTEDARGS -o "x$0" == "x" -o $0 == "bash" ]; then
echo "Usage:"
echo " Parameter 1: your webapp.com name"
exit 1
fi
WEBAPP=$0
APPFOLDER=$1
CONFFILENAME=$WEBAPP.conf
export DEBIAN_FRONTEND=noninteractive
########################################
## creating the sites-available conf file
########################################
cd /etc/nginx/sites-available
read -r -d '' FILECONTENT <<'ENDFILECONTENT'
server {
listen 80;
client_max_body_size 2M;
server_name $WEBAPP;
root /var/virtual/stage.$WEBAPP/current/src/$APPFOLDER/webroot;
access_log /var/log/nginx/cakephpsite.com-access.log;
include common.conf;
include cakephp.conf;
}
server {
listen 80;
client_max_body_size 2M;
server_name www.$WEBAPP;
rewrite ^ http://$WEBAPP$uri permanent;
}
ENDFILECONTENT
echo "$FILECONTENT" > /etc/nginx/sites-available/$CONFFILENAME
########################################
## setting the symlink
########################################
ln -s /etc/nginx/sites-enabled/$CONFFILENAME /etc/nginx/sites-available/$CONFFILENAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment