Using CherryPy to work around a Django/flup bug
A bug creeped in one of my Django 1.1 projects that is in beta-testing right now: the Pinax wiki app looks for a REMOTE_ADDR value in request.META, which was not set in my environment. My environment is a pretty standard (as far as this setup goes) nginx + fcgi (flup on the django side) + django. Further work on this issue revealed, step by step, that:
- REMOTE_ADDR needs to be somehow set by a Django middleware, based on an http header,
- so I've added django.middleware.http.SetRemoteAddrFromForwardedFor to the list of loaded middleware
- but that middleware is deprecated in Django 1.1 and does nothing, so I rewrote this middleware based on Chapter 15 of Django Book
- this new middleware did its job, but for some reason flup stripped that header from the request and the proper values never got to Django
- this made me look for a replacement for flup, which I found in django-cpserver.
This package adds a new admin command, 'runcpserver', which replaces the default development server by something more appropriate to production. The word on the 'net-streets' is that it runs well and does its job, so I'll be using it for the time being. The recommended solution is to run apache+mod_wsgi and proxy that to nginx, but right now I don't want the extra administrative overhead that Apache represents. If I can't get enough "juice" out of one instance of cpserver, I'll just add an extra instance and balance them with nginx or haproxy.