Created
April 15, 2011 13:22
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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