tags:

views:

70

answers:

1

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
sys.path.append("shoout_web")
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()
    pool.start()
    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)
        else: 
            return WSGIRoot.getChildWithDefault(name, request)

# Attaching proxy + django 
log_dir = './.log'
if not os.path.exists(log_dir):
    os.makedirs(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?

A: 

It is not clear to me why you want to use a reverse-proxy. I think you're trying to use the right tool for the wrong reasons.

Reverse proxy is useful because you can have a lightweight server like nginx handle thousands of http keep-alive connections with very little memory overhead. The connections between the reverse proxy and the real web server (twisted in your case) are fewer and short-lived by comparison, thus you can handle higher loads. Note that if you're using long-lived comet connections, there's no benefit here, because you need the connection open in both servers for the duration.

You seem to be wanting to use it to simply make the server on port 12345 available on port 80. This is not what a reverse-proxy is for. Why not just bind port 80 in the first place?

Eloff
Well I have port 80 running django. My comet server is running on port 12345. Most companies block that non standard port. So I looked into reverse proxying http://mysite.com:80/orbited/* -> localhost:12345/* (with respect to the server) and http://mysite.com:80/* (except the first rule) to go to localhost:80/* (for django)
disappearedng
The else part that you asked about, that's where you reverse-proxy to the server running django (say on port 8080, because port 80 is your proxy. Now if you're running django with apache like most people, then you can simply use apache (on port 80) to reverse-proxy requests for /orbited to the comet server. You can do this with just about any web-server setup. Listen on port 80, check for /orbited, reverse-proxy that to comet server, else handle with django. I'd need specific details on your setup to give you more specific advice, but you should get the general idea.
Eloff