Skip to content

Instantly share code, notes, and snippets.

@inkel
Last active August 29, 2015 13:57
Show Gist options
  • Save inkel/9411931 to your computer and use it in GitHub Desktop.
Save inkel/9411931 to your computer and use it in GitHub Desktop.
# -*- mode: nginx -*-
# This is required 'cause otherwise your application will see all
# requests as coming from 127.0.0.1 instead of the real user
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
# This defines the "upstream", that is the list of servers that will
# be proxied by nginx. The more servers you have the faster the app will
# respond in most cases.
upstream job_board {
server 127.0.0.1:8080 fail_timeout=0;
}
# HTTP frontend
server {
server_name jobs.punchgirls.com;
listen 80 default;
# This tells the server that ALL request done using HTTP should be
# permanently redirected to HTTPS.
location / {
rewrite ^(.*) https://jobs.punchgirls.com$1 permanent;
}
}
server {
listen 443 default_server ssl;
server_name jobs.punchgirls.com;
# SSL configuration
ssl on;
ssl_certificate /etc/nginx/jobs.punchgirls.com.crt;
ssl_certificate_key /etc/nginx/jobs.punchgirls.com.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;
# Leave it as it is for now
# add_header Vary Accept;
# gzip on;
# gzip_min_length 1000;
# gzip_proxied expired no-cache no-store private auth;
# gzip_types text/plain application/xml application/x-javascript application/javascript text/css;
# gzip_disable "MSIE [1-6]\.";
# gzip_vary on;
# This tells nginx where to look for your static files
root /home/ubuntu/job_board/public;
# This tells nginx to try to find the static file first, otherwise send it to @app
try_files $uri @app;
# This defines @app as everything that will be sent to the app server
location @app {
# Add custom headers
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
# `job_board` is the name of the upstream defined at the top of the file
proxy_pass http://job_board;
}
}
#! /bin/sh
### BEGIN INIT INFO
# Provides: webserver
# Required-Start: $syslog $remote_fs
# Required-Stop: $syslog $remote_fs
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: webserver - Persistent key-value db
# Description: webserver - Persistent key-value db
### END INIT INFO
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
PIDFILE=/var/run/webserver.pid
DAEMON=/usr/local/bin/rackup
DAEMON_ARGS="-s thin -D -a 127.0.0.1 -p 8080 -P $PIDFILE"
NAME=webserver
DESC=webserver
test -x $DAEMON || exit 0
set -e
case "$1" in
start)
echo -n "Starting $DESC: "
if start-stop-daemon --start --chdir /home/ubuntu/job_board --quiet --umask 007 --exec /usr/bin/env -- $(cat /home/ubuntu/job_board/env.sh) $DAEMON $DAEMON_ARGS
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if kill $(cat $PIDFILE)
then
echo "$NAME."
else
echo "failed"
fi
while test -f $PIDFILE; do
sleep 1
done
;;
restart)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment