【问题标题】:Cherrypy 3.2 virtual host dispatcherCherrypy 3.2 虚拟主机调度器
【发布时间】: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


【解决方案1】:

它们在cherrypy 文档中显示的端口是“80”以外的值。 curl 至少,如果端口为 80,则不会在 Host 请求头中添加端口号;我怀疑cherrypy.dispatch.VirtualHost 不够聪明,无法将端口80 上的example.com 主机头匹配到example.com:80,反之亦然。我可能会在配置中映射两个主机(有和没有端口号),以防不寻常的主机标头碰巧从线路上下来。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-20
    • 2010-10-17
    • 2010-09-24
    • 2010-10-07
    • 1970-01-01
    • 2020-04-14
    • 2014-07-06
    • 2014-09-08
    相关资源
    最近更新 更多