【发布时间】:2011-06-29 13:07:36
【问题描述】:
我正在尝试让虚拟主机在运行在 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使用'server.socket_port'选项在端口80上服务,但你的虚拟主机都有8000端口...
-
我真的希望,这就是问题所在。我将 vhosts 端口更改为 80,但没有任何改变。我仍然在所有测试域上获得 Root 页面。还有其他想法吗?
-
虚拟主机描述中应该有端口吗?
-
@TokenMacGuy:是的!它现在正在工作。我删除了虚拟主机端口,它正在工作。很奇怪,因为文档示例使用带有虚拟主机的端口。 tools.cherrypy.org/wiki/VirtualHosts非常感谢!
标签: python python-3.x cherrypy virtualhost