我正在尝试让虚拟主机在 python 3 上运行的 cherrypy 3.2.0 中工作:
#!/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"
})
}
}
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()
我已经在/etc/hosts 中登记了测试域。请求时,它们被正确定向到服务器。 但是,即使我转到 testingdomain.com 或 testingdomain2.com,我得到的唯一页面是 Root。
有人可以帮帮我吗?
最佳答案
他们在 cherrypy 文档中显示的端口值不是“80”。 curl
至少,如果端口为80,则不在Host
请求头中添加端口号;我怀疑 cherrypy.dispatch.VirtualHost
不够聪明,无法将端口 80 上的 example.com
的主机 header 匹配到 example.com:80
反之亦然。我可能会在配置中映射两个主机(有和没有端口号),以防不寻常的主机头碰巧从线路上掉下来。
关于python - Cherrypy 3.2 虚拟主机调度程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6521126/