diff --git a/docs/examples/nginx_gunicorn/gunicorn_start b/docs/examples/nginx_gunicorn/gunicorn_start new file mode 100755 index 0000000..f35ae7e --- /dev/null +++ b/docs/examples/nginx_gunicorn/gunicorn_start @@ -0,0 +1,36 @@ +#!/bin/bash + +export MPLCONFIGDIR="/srv/nsupdate/run/" + +NAME="nsupdate.info" # Name of the application +DJANGODIR=/srv/nsupdate/nsupdate/nsupdate # Django project directory +SOCKFILE=/srv/nsupdate/run/gunicorn.sock # communication socket +PIDFILE=/srv/nsupdate/run/gunicorn.pid +USER=www-data # the user to run as +GROUP=www-data # the group to run as +NUM_WORKERS=3 # how many worker processes should Gunicorn spawn +DJANGO_SETTINGS_MODULE=nsupdate.settings # which settings file should Django use +DJANGO_WSGI_MODULE=nsupdate.wsgi # WSGI module name + +echo "Starting $NAME" + +# Activate the virtual environment +cd $DJANGODIR +source /srv/nsupdate/bin/activate +export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE +export PYTHONPATH=$DJANGODIR:$PYTHONPATH + +# Create the run directory if it doesn't exist +RUNDIR=$(dirname $SOCKFILE) +test -d $RUNDIR || mkdir -p $RUNDIR + +# Start your Django Unicorn +# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon) +exec /srv/nsupdate/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \ + --name $NAME \ + --workers $NUM_WORKERS \ + --user=$USER --group=$GROUP \ + --log-level=debug \ + --bind=unix:$SOCKFILE \ + --pid $PIDFILE + diff --git a/docs/examples/nginx_gunicorn/nginx.conf b/docs/examples/nginx_gunicorn/nginx.conf new file mode 100644 index 0000000..c6a8449 --- /dev/null +++ b/docs/examples/nginx_gunicorn/nginx.conf @@ -0,0 +1,49 @@ +upstream nsupdate_server { + server unix:/srv/nsupdate/run/gunicorn.sock fail_timeout=0; +} + +server { + listen :80; + server_name nsupdate.info; + return 301 http://www.nsupdate.info$request_uri; +} + +server { + + listen :80; + listen [::]:80; + server_name nsupdate.info ipv4.nsupdate.info ipv6.nsupdate.info; + server_tokens off; + + client_max_body_size 4G; + + access_log /srv/nsupdate/logs/nginx-access.log; + error_log /srv/nsupdate/logs/nginx-error.log; + + location /favicon.png { + alias /srv/nsupdate/static/favicon.png; + } + + location /static/ { + alias /srv/nsupdate/static/; + } + + location / { + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + # when doing https + # proxy_set_header X-Forwarded-Proto https; + proxy_set_header Host $http_host; + proxy_redirect off; + + if (!-f $request_filename) { + proxy_pass http://nsupdate_server; + break; + } + } + + # Error pages + error_page 500 502 503 504 /500.html; + location = /500.html { + root /srv/nsupdate/static/; + } +} diff --git a/docs/examples/nginx_gunicorn/supervisor.conf b/docs/examples/nginx_gunicorn/supervisor.conf new file mode 100644 index 0000000..1b0ce6d --- /dev/null +++ b/docs/examples/nginx_gunicorn/supervisor.conf @@ -0,0 +1,5 @@ +[program:nsupdate.info] +command = /srv/nsupdate/bin/gunicorn_start ; Command to start app +user = www-data ; User to run as +stdout_logfile = /srv/nsupdate/logs/gunicorn_supervisor.log ; Where to write log messages +redirect_stderr = true ; Save stderr in the same log