The configuration we introduce here is useful for heavy loaded production sites.
SCGI is a light protocol that is similar in scope to FCGI, but designed to be much simpler
and lighter on the network.
To make web2py work with SCGI we have to consider that web2py is by all means a WSGI
application. There are a lot of examples on how to make WSGI talk SCGI, but of course web2py
has already a small SCGI<->WSGI server included.
Before we can start using it we must choose a SCGI implementation for python. We suggest
wsgitools. We can install the python package:
# pip install wsgitools
or
# easy_install wsgitools
now we can start web2py as a SCGI server:
$ cd <web2py installation root>
$ python scgihandler.py & #start the server in background
$ disown $! #detach the server from the terminal. You can close the terminal afterwards.
Now we would like to serve the pages through HTTP not SCGI! So what we need is a web server that can speak to SCGI backends. We need a fast one and easy to configure, so we choose nginx.
Since nginx comes with a nice SCGI module we need only to write a little piece of configuration in nginx.conf (usually under /etc/nginx). In a server section of choice put the following
set $web2pyroot <web2py root folder>;
#serve static content without web2py intervention
location ~ ^/(.*)/static/(.*) {
alias $web2pyroot/applications/$1/static/$2;
}
# use port 4000 the default definend in scgihandler.py
location / {
include /etc/nginx/scgi_params;
scgi_pass 127.0.0.1:4000;
}
Start nginx and we are done. Was that fast? See it running!
telloroberto...
rajaram_s
howesc
titogarrido