Topics relating to Configuration of Akara
Running apps behind a reverse proxy
It's common to run WSGI apps behind a reverse proxy, such as Apache's mod_proxy, and this can make it difficult to reliably construct portable URLs within the application. APACHE forwards the original request host name (and port) using the X_FORWARDED_HOST header, but in common cases this loses the original HTTP request path, and in theory could lose the original scheme as well. The the case of the following Apache directive, set up to handle requests on http://example.com and proxying to a local WSGI server on port 8080:
ProxyPassReverse /spam/ http://localhost:8080/eggs/
If the user requests:
http://example.com/spam/monty
This will be proxied so that the WSGI server sees an HTTP request such as:
GET /eggs/monty HTTP/1.1 Host: www.example.com X-Forwarded-Host: example.com
It has no way to see the /spam component from the original request, which is a problem because the WSGI app needs that component to construct URLs that will work properly for the original user agent.
Paste users can deal with this by using paste.deploy.config.PrefixMiddleware. In the above example is you set PrefixMiddleware.prefix to /spam, then it would fix environ['PATH_INFO'] for wrapped apps so that they see /spam rather than the less useful /eggs. This would, for example, allow akara.util.url() work without any further config by the user.
Non-Paste users dealing with this problem can configure things for akara.util.url() by setting environ['akara.proxy-base'] to the full base URL to be used. In the above example this would be http://example.com/spam/.
Note: for Lighttpd , the problem is similar except that it uses X-Host rather than X-Forwarded-Host to preserve the original request host. Lighttpd does seem to allow you to customize headers for reverse proxy situations (see: http://trac.lighttpd.net/trac/wiki/Docs:ModProxyCore)
Side note: Apache mod_proxy sets several useful headers:
- HTTP_X_FORWARDED_FOR
- The IP address of the client.
- HTTP_X_FORWARDED_HOST
- The original host requested by the client in the Host HTTP request header.
- HTTP_X_FORWARDED_SERVER
- The hostname of the proxy server.
(via http://askapache.info/trunk/mod/mod_proxy.html#x-headers)
