Cherrypy虚拟主机-单独的应用程序配置



我想在同一IP上的不同域上放置两个cherrypy应用程序。如何使用cherrypy-virtualhostdispatcher为这些站点提供单独的配置文件,而不将cherrypy web服务器隐藏在Apache后面?

import cherrypy
from cherrypy import expose
class Root(object):
    @expose
    def index(self):
        return "The Main Page" + 
          '<br /><a href="/rs/file.txt">File from the Main app</a>'
class SecondApp(object):
    @expose
    def index(self):
        return "Page on Subdomain" + 
          '<br /><a href="/rs/file.txt">Another file from the subdomain app</a>'
def main():
    cherrypy.config.update('global.conf')
    conf = {"/": {"request.dispatch": cherrypy.dispatch.VirtualHost(
                    **{ "sub.domain.local": "/secondapp" } )
                 }
           }
    root = Root()
    root.secondapp = SecondApp()
    app=cherrypy.tree.mount(root, "/", conf)
    app.merge('some.additional.configuration')
    cherrypy.engine.start()
    cherrypy.engine.block()
if __name__ == "__main__": main()

"conf"词汇表定义的配置对我的域"domain.local"one_answers"sub.domain.local"都有影响。如何在此处插入应用程序"secondapp"的单独配置?

您需要稍微更改main。您必须添加另一个配置部分,然后使用cherrypy.tree.mount将其与conf对象一起添加。

def main():
    conf = {"/": {"request.dispatch": cherrypy.dispatch.VirtualHost(
                    **{ "sub.domain.local": "/secondapp" } )
                 }
           }
    secondapp_conf = {
        ... Config Items for Second App ....
        }
    }
    root = Root()
    root.secondapp = SecondApp()
    cherrypy.tree.mount(root, "/", conf)
    cherrypy.tree.mount(root.secondapp, "/secondapp", secondapp_conf)
    cherrypy.engine.start()
    cherrypy.engine.block()

相关内容

最新更新