#38 Twisted reverse proxy support


I run twistedmoin behind an Apache reverse proxy using
mod_proxy. Everything works fine, but the RSS feed
shows the internal host/port as source instead of the
published URL (i.e. the reverse proxy host/port).

adding these two lines to MoinRequest(server.Request):

if getattr(config, 'proxyhost', None) and
getattr(config, 'proxyport', None):
self.setHost(config.proxyhost, config.proxyport,
ssl=getattr(config, 'proxyssl', 0))

self.host = self.channel.transport.getHost()


seems to solve the problem. Obviously, this is a quick
and dirty hack and I am not sure, if this has some bad
side effects I am not aware of. I am also not sure, if
it is the right place to do it. And, of course it would
be better to include some default settings in the
Config class for the new config attributes proxyhost,
proxyport and proxyssl instead of the getattr quirk.

BTW, this is the docstring of setHost in
"""Change the host and port the request thinks it's
using. This method is useful for working with reverse
HTTP proxies (e.g. both Squid and Apache's mod_proxy
can do this), then the address the HTTP client is using
is different than the one we're listening on.
For example, Apache may be listening on
https://www.example.com, and then forwarding requests
to http://localhost:8080, but we don't want HTML
produced by Twisted to say 'http://localhost:8080',
they should say 'https://www.example.com', so we do::
request.setHost('www.example.com', 443, ssl=1)
This method is experimental.


  • Alexander Schremmer

    • priority: 5 --> 6
    • summary: twisted reverse proxy support --> Twisted reverse proxy support
  • Thomas Waldmann

    Thomas Waldmann - 2005-01-23

    Logged In: YES

    the current 1.3 development version (soon to be released as
    1.3.2) uses such code only for POST.

    so i think your patch can't be applied there.


Log in to post a comment.