If you benefit from web2py hope you feel encouraged to pay it forward by contributing back to society in whatever form you choose!

Just a quick recipe to for a Debian deployment of web2py with Nginx and SCGI.  Note that this in part based on the slice at http://www.web2pyslices.com/slice/show/1466/nginx-and-scgi

Install the requirements:

~# aptitude install nginx-full python-pip 
~# pip install wsgitools

Create /etc/ngnix/sites-available/web2py:

server {
        set $web2pyroot /var/www/web2py;

        listen 80;
        access_log /var/log/nginx/access.log;

        location ~ ^/(.*)/static/(.*) {
                alias $web2pyroot/applications/$1/static/$2;
        }
        location / {
                include scgi_params;
                scgi_pass 127.0.0.1:4000;
        }
}

Create /etc/nginx/sites-available/web2py-ssl:

server {
        set $web2pyroot /var/www/web2py;

        listen 443;
        ssl on;
        ssl_certificate /etc/ssl/certs/localhost.crt;
        ssl_certificate_key /etc/ssl/private/localhost.key;
        ssl_ciphers ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
        keepalive_timeout 70;
        access_log /var/log/nginx/access.log;

        location ~ ^/(.*)/static/(.*) {
                alias $web2pyroot/applications/$1/static/$2;
        }
        location / {
                include scgi_params;
                scgi_param HTTPS yes;
                scgi_pass 127.0.0.1:4000;
        }
}

Note that the keepalive directive requires Nginx v1.1.4 or above (version in Squeeze is 0.7.67-3+squeeze2).

Disable the defautl site and enable web2py:

~# rm /etc/nginx/sites-enabled/default
~# ln -s /etc/nginx/sites-available/web2py /etc/nginx/sites-enabled/
~# ln -s /etc/nginx/sites-available/web2py-ssl /etc/nginx/sites-enabled/

Create /etc/init.d/scgihandler script:

#!/bin/sh

### BEGIN INIT INFO
# Provides:          scgihandler
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the scgi handler
# Description:       starts scgi using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON="/usr/bin/env python"
ARGS=/var/www/web2py/scgihandler.py
NAME=scgihandler
DESC="web2py scgihandler"

set -e

. /lib/lsb/init-functions

case "$1" in
        start)
                echo -n "Starting $DESC: "
                start-stop-daemon --start --background --quiet --pidfile /var/run/$NAME.pid \
                    --make-pidfile --exec $DAEMON $ARGS || true
                echo "$NAME."
                ;;

        stop)
                echo -n "Stopping $DESC: "
                start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid || true
                echo "$NAME."
                ;;

        restart|force-reload)
                echo -n "Restarting $DESC: "
                start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid || true
                sleep 1
                start-stop-daemon --start --background --quiet --pidfile /var/run/$NAME.pid \
                    --make-pidfile --exec $DAEMON $ARGS || true
                echo "$NAME."
                ;;

        status)
                status_of_proc -p /var/run/$NAME.pid "$DAEMON" scgihandler && exit 0 || exit $?
                ;;
        *)
                echo "Usage: $NAME {start|stop|restart|force-reload|status}" >&2
                exit 1
                ;;
esac

exit 0

Add to standard init and start the scgihander:

~# update-rc.d scgihandler defaults
~# /etc/init.d/scgihandler start

Restart Nginx:

~# /etc/init.d/nginx restart

If you want to access the /admin interface, you'll also need a /var/www/web2py/parameters_443.py.  Note that 443 is the SSL port.  If copying from your local web2py location, use the corresponding file.

Related slices

Comments (0)


Hosting graciously provided by:
Python Anywhere