python - Apache mod_rewrite 与多个 Web 应用程序

标签 python apache mod-rewrite cherrypy

我已经编写了 2 个独立的 Cherrypy Web 应用程序,需要使用 mod_rewrite 或类似的东西将它们放在 Apache 后面。需要通过 http://domain.com/WebApp1 访问它们和 http://domain.com/WebApp2 。到目前为止,我已经弄清楚如何创建单个虚拟主机,但只能通过 http://domain.com/ 访问它。 。 Apache 执行此操作的正确配置是什么?我应该使用 mod_rewrite 以外的东西吗?

最佳答案

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

像这样在cherrypy树中安装每个应用程序:

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 .

关于python - Apache mod_rewrite 与多个 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14404469/

相关文章:

apache - 重定向错误 : Wordpress + Let's Encrypt (Certbot) + SSL only + non-www

php - htaccess 中的 mod_rewrite 是否有助于防止注入(inject)?

php - Nextcloud 21 升级 : Cannot write into "config" directory

java - Java Jersey 中的地理位置

cakephp - 我如何在 CakePHP 中启用 SEO 友好的 URL?

python - 由于 PyQt5.QtWebKitWidgets 无法启动 spyder

ruby-on-rails - 将 apache SSL 反向代理与 Rails 应用程序结合使用

python - wxPython - 如何在传入 -1 时获取小部件的 ID?

python - SQLAlchemy 中的动态类创建

python - BeautifulSoup (bs4) : How to ignore ending tag in malformed HTML