1

我已经编写了 2 个独立的 Cherrypy Web 应用程序,需要使用 mod_rewrite 或类似的东西将它们都放在 Apache 后面。需要在http://domain.com/WebApp1http://domain.com/WebApp2访问它们。到目前为止,我想出了如何做一个虚拟主机,但它只能在http://domain.com/访问。Apache 的正确配置是什么?我应该使用 mod_rewrite 以外的东西吗?

4

1 回答 1

2

如果这两个应用程序是用cherrypy制作的,你可以避免使用mod_rewrite。

像这样在樱桃树中挂载每个应用程序:

import cherrypy

from webapp1 import WebApp1
from webapp2 import WebApp2

cherrypy.tree.mount(WebApp1, '/WebApp1')
cherrypy.tree.mount(WebApp2, '/WebApp2')
cherrypy.engine.start()
cherrypy.engine.block()

例如:

 import cherrypy

 class AppOne(object):
     def index(self):
         return 'Hi from app one!'
     index.exposed = True

 class AppTwo(object):
     def index(self):
         return 'Hi from app two!'
     index.exposed = True

 if __name__ == '__main__':
     cherrypy.tree.mount(AppOne(), '/app1')
     cherrypy.tree.mount(AppTwo(), '/app2')
     cherrypy.engine.start()
     cherrypy.engine.block()

或者:

 import cherrypy

 class AppOne(object):
     def index(self):
         return 'Hi from app one!'
     index.exposed = True

 class AppTwo(object):
     def index(self):
         return 'Hi from app two!'
     index.exposed = True

 class Root(object):
     app1 = AppOne()
     app2 = AppTwo()

 if __name__ == '__main__':
     cherrypy.tree.mount(Root())
     cherrypy.engine.start()
     cherrypy.engine.block()
     # cherrypy.quickstart(Root()) # is the same

另一种选择是使用mod_proxy

于 2013-01-19T20:32:30.123 回答