This recipe explains how to run web2py behind a Cherokee web server using uWSGI.
Cherokee is a webserver written in C, similar in intent to Lighttpd: fast, compact, and modular. Cherokee comes with an administrative interface that allows one to manage its configuration, which is difficult to read and modify otherwise. uWSGI is described in its website as a fast (pure C), self-healing, developer/sysadmin-friendly application container server. Cherokee has an included module to talk to uWSGI servers.
Install the package or download, compile, and install the required components. Create the following file in the installation root of web2py, and call it
uwsgi.xml
:<uwsgi> <pythonpath>/home/web2py</pythonpath> <module>wsgihandler</module> <socket>127.0.0.1:37719</socket> <master/> <processes>8</processes> <memory-report/> </uwsgi>
This configuration spawns eight processes to manage multiple requests from the HTTP server. Change it as needed, and configure
<pythonpath>
to the installation root of web2py.As the user that owns the web2py installation, start the uWSGI server:
$ uWSGI -d uwsgi.xml
Now launch the Cherokee administrative interface to create a new configuration:
$ cherokee-admin
Connect to the admin interface with the browser at the following link:
http://localhost:9090/
.Go to the Sources section - (A), then click on the + button - (B).
Select Remote Host on (C), then fill the text field at (D) with the IP address, and port to match the configuration in the previous
uswgi.xml
file.Having configured the uWGI source, it is now possible to configure a Virtual Host, and redirect requests through it. In this recipe, we choose the default Virtual Host that is used when no other Virtual Host has a better match for the incoming request.
Click on button
(C)
to go to Rule Management.Delete all rules listed on the left. Only the default rule will remain.
Configure the default rule with a uWSGI Handler. Leave the other values unchanged.
If you want Cherokee to serve static files directly from web2py folders, you can add a Regular Expression rule. Click button (A), and select Regular Expression from the drop-down menu at (B). Be aware that this configuration works only if the web2py directory is on the same file system, and is accessible to Cherokee.
Configure the Regular Expressions:
Now you can configure the Static Handler pointing to the applications subdirectory of your web2py installation:
Remember to save the configuration, and reload or restart Cherokee from the administrative interface; then you are ready to start the uWSGI server.
Change to the correct user ID that was used to install web2py; be aware that using root is not recommended.
Go into the root directory of web2py installation, where you saved the configuration file
uwsgi.xml
.Run uWSGI with the
-d <logfile>
option, so that it runs in the background:$ su - <web2py user> $ cd <web2py root> $ uwsgi -x uwsgi.xml -d /tmp/uwsgi.log
Enjoy the speed!
You should have the following:
web2py (installed but not running)
uWSGI (download and install from http://projects.unbit.it/uwsgi/wiki)
Cherokee (download and install from http://www.cherokee-project.com/)