Archive for March, 2013

How to run a Flask application in a subpath, using Apache mod_proxy

Although there are much better solutions for running wsgi applications (mod_wsgi for Apache or uwsgi, gunicorn for nginx), I’ve been cracking my head trying to set it up using mod_proxy and in a subpath.

What I wanted to achieve is: <-> http://localhost:5000/ ->

(because http://localhost:5000/redir -> http://localhost:5000/destination)

Said and done, having an instance of the app running on :5000, most of the pages on the internet suggest the next apache configuration (including the mod_proxy official docs):

ProxyPass /appname/  http://localhost:5000/
ProxyPassReverse /appname/ http://localhost:5000/

Wrong! The correct setup, for a domain, is:

ProxyPass /appname/ http://localhost:5000/
ProxyPassReverse /appname/

The explanation stays in the ProxyPassReverse reference: it will will do a string replace in the HTTP Location headers. Our app redirects to, which translates to /appname/ (because of ProxyPassReverse), which translates to our localhost:5000 server (because of ProxyPass).

Please correct me if I’m wrong, but this was the only setup proved to be working.