Why bother covering this again?

Many existing hints, often part of the documentation of popular Python web application-related projects, show simple, working nginx configuration but nothing equivalent for Apache httpd — sometimes nothing at all, sometimes something very crufty.

I'm not aware of any small number of sources that cover as many considerations, especially in a consistent manner.

Nothing but modern levels of Apache httpd and nginx!

Apache httpd 2.4.latest, nginx 1.6.latest

uWSGI as the tool for managing application processes

Why uWSGI? Besides being well respected, well documented, and well maintained:

  • uWSGI is easy to run in the shell and easy to configure in a more obvious way for production use, so you end up always testing your application and web server configuration with the same protocol engine.
  • uWSGI supports all the common communication mechanisms between web servers and Python applications so if you need to change the protocol for some reason all other behavior and configuration can remain the same.
  • Last but not least, unbit has been extremely responsive in resolving issues I've found while researching this tutorial.

(I have some coverage of alternatives to uWSGI, notably Gunicorn, starting here. See also A Comparison of Web Servers for Python Based Web Applications.)

Clearly I'm diverging from the historical means of running Python web apps with httpd — mod_wsgi, mod_fcgid, or other plug-ins that manage the application lifecycle in addition to routing requests to the applications. There are several reasons for this:

  • Those plug-in modules are not getting nearly as much attention as the pure gateway support based on mod_proxy.
  • The ability to mix and match web server, protocol, socket type, application process lifecycle management, etc. is good for the your project in the long term, and allows you to reuse aspects of other deployments even if some of the pieces are different.
  • Avoiding httpd-specific solutions makes it easy to provide alternative httpd and nginx deployment instructions that differ very little.

Issues with specific versions

The baseline software versions used for this tutorial were httpd 2.4.10, nginx 1.6.0, and uWSGI 2.0.5. In the cases outlined below, you are likely to encounter problems or limitations with certain older versions of this software:

httpd 2.4.9

mod_proxy_fcgi crash if backend isn't listening (fixed in httpd 2.4.10)

mod_proxy_scgi: no support for Unix sockets (fixed in httpd 2.4.10)

uWSGI 2.0.4

issue with FastCGI protocol handling, resulting in intermittent request failures with httpd's mod_proxy_fcgi; could conceivably affect deployments with nginx, but I didn't encounter that

This fix was in uWSGI 2.0.5, released in June of 2014. If you installed uWSGI previously and you want to use FastCGI with httpd's mod_proxy_fcgi, upgrade first.

nginx 1.6.0

Some undiagnosed misbehavior is listed on the last page of this tutorial.