#!/usr/bin/env python """ This is based on: Tutorial - Hello World """ # Import CherryPy global namespace import cherrypy class MyRoot: """ My Root. """ def index(self, *args): print args return "Hello world!" index.exposed = True class stats: """ Stats dir providing 'static' png images. """ def index(self): return """ Stats page





""" index.exposed = True class blog: """ Sample for /blog/bla/blo, where bla and blo are args. """ def default(self,*args): #def default(self, year="", month="", day=""): print cherrypy.request.headers['Host'] #print "%s-%s-%s" % (year,month,day) return ("%s %s %s %s" % (args[0],args[1],args[2],args[3])) #index.exposed = True default.exposed = True class VHost: def __init__(self, sitename): self.sitename = sitename def index(self): print cherrypy.request.headers['Host'] return "Welcome to %s" % self.sitename index.exposed = True import os.path conf = os.path.join(os.path.dirname(__file__), 'vhost.conf') if __name__ == '__main__': root = MyRoot() root.stats = stats() root.start = VHost("Server IP host") root.blog = blog() cherrypy.config.update(conf) vconf = { "/": { "request.dispatch": cherrypy.dispatch.VirtualHost( **{ "vhost1.example.com:8080": "/stats", "vhost2.example.com:8080": "/stats", "vhost3.example.com:8080": "/blog" } ) }, "/stats": { 'tools.staticdir.on': True, 'tools.staticdir.dir': 'stats' } } cherrypy.tree.mount(root, "/", vconf) cherrypy.server.quickstart() cherrypy.engine.start() else: print "Doh" // Config file.. [global] server.log_to_screen = True server.environment = "experimental" server.socket_port = 8080 server.socket_host = "" tools.staticdir.root = '/path/to/www' [/start] tools.staticdir.on = False tools.staticdir.dir = 'start'