mod_rewrite while persisting client ips
Hi there. I'm writing to the list in case someone finds this useful, I include short ProxyIPResource-'hack' and corresponding rewriterule to set request.client.host correctly :) here it goes: --snip-- from twisted.application import service, internet from nevow import rend, loaders, appserver, vhost, inevow from nevow import tags as T """ Example apache configuration NameVirtualHost * <VirtualHost *> RewriteEngine on RewriteRule (.*)/ http://localhost:8080/proxyip/%{REMOTE_HOST}/vhost/http/test.com/$1 [P] ServerName test.com </VirtualHost> """ class ProxyIPResource: __implements__ = inevow.IResource, def putChild(self, child, res): setattr(self, 'child_%s' % (child,), res) def locateChild(self, ctx, segments): if len(segments) < 1: return rend.NotFound elif "child_%s" % (segments[0],) in self.__dict__: return self.__dict__['child_%s' % (segments[0],)], segments[1:] else: request = inevow.IRequest(ctx) request.client.host = segments[0] prefixLen = len('/'+'/'.join(request.prepath)+'/'+'/'.join(segments[:1])) request.path = '/'+'/'.join(segments[1:]) request.uri = request.uri[prefixLen:] request.prepath = request.prepath[2:] return self, segments[1:] class Simple(rend.Page): addSlash = True docFactory = loaders.stan( T.html[ T.body[ T.h1["hello"] ] ]) application = service.Application("Simple") res = Simple() vResource = vhost.VHostMonsterResource() pResource = ProxyIPResource() res.putChild('proxyip', pResource) pResource.putChild('vhost', vResource) internet.TCPServer(8080, appserver.NevowSite(res)).setServiceParent(application) --snip--
I've been searching for a potential solution to this 'loss of client ip' problem for a long time. On Wed, 20 Oct 2004 10:34:17 +0300 (EEST), Miika Keskinen <weeti@usr.fi> wrote:
Hi there.
I'm writing to the list in case someone finds this useful, I include short ProxyIPResource-'hack' and corresponding rewriterule to set request.client.host correctly :)
here it goes:
--snip--
from twisted.application import service, internet
from nevow import rend, loaders, appserver, vhost, inevow from nevow import tags as T
""" Example apache configuration
NameVirtualHost *
<VirtualHost *> RewriteEngine on RewriteRule (.*)/ http://localhost:8080/proxyip/%{REMOTE_HOST}/vhost/http/test.com/$1 [P] ServerName test.com </VirtualHost>
"""
class ProxyIPResource: __implements__ = inevow.IResource,
def putChild(self, child, res): setattr(self, 'child_%s' % (child,), res)
def locateChild(self, ctx, segments): if len(segments) < 1: return rend.NotFound
elif "child_%s" % (segments[0],) in self.__dict__: return self.__dict__['child_%s' % (segments[0],)], segments[1:]
else: request = inevow.IRequest(ctx) request.client.host = segments[0]
prefixLen = len('/'+'/'.join(request.prepath)+'/'+'/'.join(segments[:1])) request.path = '/'+'/'.join(segments[1:]) request.uri = request.uri[prefixLen:] request.prepath = request.prepath[2:] return self, segments[1:]
class Simple(rend.Page): addSlash = True docFactory = loaders.stan( T.html[ T.body[ T.h1["hello"] ] ])
application = service.Application("Simple")
res = Simple()
vResource = vhost.VHostMonsterResource() pResource = ProxyIPResource()
res.putChild('proxyip', pResource) pResource.putChild('vhost', vResource)
internet.TCPServer(8080, appserver.NevowSite(res)).setServiceParent(application)
--snip--
_______________________________________________ Twisted-web mailing list Twisted-web@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web
participants (2)
-
Miika Keskinen
-
Seun Osewa