2011-06-29 39 views
3

我試圖讓虛擬主機的CherryPy 3.2.0工作乳寧對蟒蛇3:CherryPy的3.2虛擬主機調度

#!/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中。請求時,它們被正確引導到服務器。 但我得到的唯一頁面是Root,即使我去了testingdomain.com或testingdomain2.com。

有人可以幫我嗎?

+0

你告訴cherrypy通過'server.socket_port'選項服務於80端口,但你的虛擬主機都有端口8000 ... – SingleNegationElimination

+0

我真的很希望,那就是問題所在。我將虛擬主機端口改爲80,但沒有任何改變。我仍然在所有測試域上獲得Root頁面。任何其他想法? – JoshuaBoshi

+0

虛擬主機描述中是否應該有一個端口? – SingleNegationElimination

回答

2

它們在cherrypy文檔中顯示的端口是「80」以外的值。至少curl,如果端口爲80,則不會將端口號添加到Host請求標頭;我懷疑cherrypy.dispatch.VirtualHost不夠巧妙,以匹配端口80上的主機頭example.comexample.com:80或反之亦然。我可能會將兩臺主機(帶和不帶端口號)映射到配置中,以防萬一不尋常的主機頭碰到電線。

+0

再一次,非常感謝你幫助我:-) – JoshuaBoshi