【问题标题】:Nothing is rendered when using a Twisted Reverse Proxy behind a static URL path在静态 URL 路径后面使用 Twisted Reverse Proxy 时不呈现任何内容
【发布时间】: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 时有效

有人有什么想法吗?

【问题讨论】:

标签: python twisted twisted.web


【解决方案1】:

反向代理只能提供后端 HTTP 服务器提供的服务。

由于您的代码看起来或多或少正确,我猜测后端 HTTP 服务器没有提供您期望的响应。

您可以尝试使用 tcpdump 或 wireshark 查看后端生成的响应 - 或使用一些特定于服务器的工具来获取更多调试信息。您也可以尝试使用您知道肯定会生成响应以验证代理是否正常工作的不同后端 HTTP 服务器。

【讨论】:

  • 因此,我将这两个站点更改为指向 www.google.com 和 www.yahoo.com,但仍然没有呈现任何内容。
  • 当我这样做时,我得到了 google url 但没有 yahoo url 的响应。
  • 是的,我真的不确定发生了什么。我认为正在进行一些重定向。我对wireshark或tcpdump一无所知。不过,我上面的答案适用于我的 2 个内部服务资源。
【解决方案2】:

所以看起来解决方案相当简单。我只需要在路径参数中添加一个/,一切都会正确呈现:

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-16
    • 2011-09-20
    • 2015-06-13
    • 2018-10-01
    • 1970-01-01
    相关资源
    最近更新 更多