带app的烧瓶。 我想要以下路线:
"/" -> my Flask app
"/foo/" -> Reverse proxy toward http://bar/
到目前为止,我没有任何反向代理,所以我的应用程序看起来像:
^{pr2}$我希望整个项目只在python中。我不想要任何Apache或nginx堆栈(该项目不打算在公共网络上)。我看到我可以使用Python WSGI服务器,比如cherrypy中的“wsgiserver”,所以我的应用程序应该是:
from cherrypy import wsgiserver
import app
d = wsgiserver.WSGIPathInfoDispatcher({
'/': app.app.wsgi_app
})
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), d)
if __name__ == '__main__':
server.start()
如果我想在“/foo”中添加反向代理,我想我只需要:
from cherrypy import wsgiserver
import app
d = wsgiserver.WSGIPathInfoDispatcher({
'/': app.app.wsgi_app,
'/foo/': SOME_WSGI_REVERSE_PROXY
})
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), d)
if __name__ == '__main__':
server.start()
所以我的问题是:
SOME_WSGI_REVERSE_PROXY
)如公认的anwser所述,以下是最终代码:
from cherrypy import wsgiserver
import wsgiproxy.app
import app
app = app.app.wsgi_app
proxy = wsgiproxy.app.WSGIProxyApp("http://bar/")
d = wsgiserver.WSGIPathInfoDispatcher({
'/': app,
'/foo/':proxy
})
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 8080), d)
if __name__ == '__main__':
try:
server.start()
except keyboardInterrupt:
server.stop()
请参阅粘贴代理中间件。在
mitmproxy公司:mitmproxy.org网站 它是一个具有反向代理功能的python代理。在
相关问题 更多 >
编程相关推荐