【发布时间】:2014-08-01 18:56:53
【问题描述】:
我想运行一个 Twisted 服务器并在不同的 URL 路径上提供各种服务。我要做的第一件事是在有人点击/app1 路径时设置反向代理。这是我到目前为止所拥有的,但是当访问 127.0.0.1/app1 时什么都没有返回,它没有中断或任何东西,只是得到一个空白页。
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.web import proxy, server
site1 = proxy.ReverseProxyResource('127.0.0.1', 3003, '')
site2 = proxy.ReverseProxyResource('127.0.0.1', 3004, '')
root = Resource()
root.putChild("app1", site1)
root.putChild("app2", site2)
reactor.listenTCP(8090, Site(root))
reactor.run()
我已经成功地得到了一些看起来像这样的东西:
from twisted.internet import reactor
from twisted.web.server import Site
from twisted.web.resource import Resource
from twisted.web import proxy, server
site = proxy.ReverseProxyResource('127.0.0.1', 3003, '')
reactor.listenTCP(8090, Site(site))
reactor.run()
但这仅在转到 127.0.0.1:8090 时有效
有人有什么想法吗?
【问题讨论】:
-
永远不要在问题中包含三个词:“它不起作用”——至少,除非您继续解释这意味着什么,否则不会。见sscce.org 和catb.org/esr/faqs/smart-questions.html
-
抱歉,为了澄清,做了一些修改。
标签: python twisted twisted.web