Skip to content

Instantly share code, notes, and snippets.

@j4mie
Created April 15, 2011 13:22
Show Gist options
  • Save j4mie/921672 to your computer and use it in GitHub Desktop.
Save j4mie/921672 to your computer and use it in GitHub Desktop.
A reverse proxy that sends requests to "mysubdomain.mysite.com" to a machine with a DNS entry for "mysubdomain" (untested)
from twisted.internet import reactor
from twisted.web.proxy import ReverseProxyResource
from twisted.web.server import Site
from twisted.web.resource import Resource
class DynamicSubdomainReverseProxy(Resource):
isLeaf = False
allowedMethods = ("GET", "POST", "PUT", "DELETE", "HEAD", "OPTIONS")
def getChild(self, path, request):
subdomain = request.getRequestHostname().split('.')[0]
return ReverseProxyResource(subdomain, 80, '/' + path)
proxy = DynamicSubdomainReverseProxy()
site = Site(proxy)
reactor.listenTCP(80, site)
reactor.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment