开发者

Cherrypy 3.2 virtual host dispatcher

开发者 https://www.devze.com 2023-03-16 08:50 出处:网络
i am trying to get virtual host working in cherrypy 3.2.0 runing on python 3: #!/usr/bin/env python import cherrypy

i am trying to get virtual host working in cherrypy 3.2.0 runing on python 3:

#!/usr/bin/env python

import cherrypy
from cherrypy import expose

class Root(object):

    @expose
    def index(self):
        return "I am the root  vhost"

class Foo(object):

    @expose
    def index(self):
        return "I am testingdomain.com"

class Bar(object):

    @expose
    def index(self):
        return "I am testingdomain2.com."

def main():

    cherrypy.config.update({'server.socket_host': 'rootdomain.com',
            'server.socket_port': 80,
    })

    conf = {
        "/": {
            "request.dispatch": cherrypy.dispatch.VirtualHost(
            **{
                "testingdomain.com:8000": "/foo",
                "testingdomain2.com:8000": "/bar"
            })
        }
    }

 开发者_StackOverflow中文版   root = Root()
    root.foo = Foo()
    root.bar = Bar()
    cherrypy.tree.mount(root, "", conf)

    #cherrypy.quickstart()
    cherrypy.engine.start()
    cherrypy.engine.block()

if __name__ == "__main__":
    main()

I have got testing domains enlisted in /etc/hosts. When requesting, they are correctly directed to server. But the only page i got served is Root even if I go to testingdomain.com or testingdomain2.com.

Can somebody please help me?


The ports that they show in the cherrypy docs are values other than '80'. curl at least, does not add port numbers to the Host request header if the port is 80; I suspect that cherrypy.dispatch.VirtualHost is not clever enough to match a host header of example.com on port 80 to example.com:80 or visa versa. I would probably map both hosts (with and without port numbers )in the config in case an unusual host header happens to come down the wire.

0

精彩评论

暂无评论...
验证码 换一张
取 消