[Twisted-Python] Twisted Reverse Proxy

disappearedng disappearedng at gmail.com
Sat Oct 16 13:54:30 EDT 2010

Hello everyone, I am deploying twisted as a web server for my site. I am
looking into possibilities of reverse proxying.

I have the following code right now hooked up to my reactor for django. I am
using comet, and I realize that I absolutely must use port 80 hence I am
looking into possibilities of reverse proxying. On this site, I found the
following example:

# Django setup
os.environ['DJANGO_SETTINGS_MODULE'] = 'shoout_web.settings'

def wrapper_WSGIRootWrapper():
    # Build the wrapper first
    generic = WSGIHandler()
    def HandlerWrapper(environ, start_response):
        environ['engine'] = engine
        return generic(environ, start_response)

    # Thread and Allowing Ctrl-C to get you out cleanly:
    pool = threadpool.ThreadPool()
    reactor.addSystemEventTrigger('after', 'shutdown', pool.stop)
    return wsgi.WSGIResource(reactor, pool, HandlerWrapper)
WSGIRoot = wrapper_WSGIRootWrapper()

# Reverse Proxy
class Simple(Resource):
    isLeaf = False

    def getChild(self, name, request):
        if name == "orbited":
            print "orbited"
            return proxy.ReverseProxyResource('localhost', 12345, "/"+name)
            return WSGIRoot.getChildWithDefault(name, request)

# Attaching proxy + django
log_dir = './.log'
if not os.path.exists(log_dir):
reactor.listenTCP(DJANGO_PORT, server.Site(Simple(),
logPath=os.path.join(log_dir, '.django.log')))

My trouble is I don't really know what to fill in in the else part of that
second code part. I looked at text_proxy on twisted-src and there weren't
substantial examples for this. Any help?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20101016/ba3843f8/attachment.htm 

More information about the Twisted-Python mailing list