gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:50:45 26 4
gpt4 key购买 nike

我已经编写了 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com