How to do Virtual Hosting
CHerryPy has a built-in dispatcher for supporting Virtual Hosts. See:
- http://groups.google.com/group/cherrypy-users/browse_thread/thread/f393540fe278e54d
- http://www.cherrypy.org/changeset/1655
Put simply this means you can develop an application that can serve different parts of itself for different virtual hosts. For example, say you have an application mounted at / on http://domain.com/ you could map:
- http://foo.domain.com/ -> /foo
- http://bar.domain.com/ -> /bar
Example
conf.ini
[global] server.socket_port = 8000 server.thread_pool = 10
vhosts.py
#!/usr/bin/env python import cherrypy from cherrypy import expose class Root(object): @expose def index(self): return "I am the main vhost" class Foo(object): @expose def index(self): return "I am foo." class Bar(object): @expose def index(self): return "I am bar." def main(): cherrypy.config.update("conf.ini") conf = { "/": { "request.dispatch": cherrypy.dispatch.VirtualHost( **{ "foo.domain.com:8000": "/foo", "bar.domain.com:8000": "/bar" } ) } } root = Root() root.foo = Foo() root.bar = Bar() cherrypy.tree.mount(root, "/", conf) cherrypy.server.quickstart() cherrypy.engine.start() if __name__ == "__main__": main()

