【问题标题】:Using twisted to selectively reverse proxy to different servers使用twisted有选择地反向代理到不同的服务器
【发布时间】:2018-05-29 10:26:22
【问题描述】:

我目前正在使用 Twisted(实际上是 twistd)来提供这样的内容:

twistd -n -o web --path=./foo/

没关系,但我想向另一台服务器发送一些请求 - 像这样。

当客户端请求时

localhost/something.html

我希望twistd 服务器处理该请求。

但是当客户端请求时

localhost/api/somedata

我希望将请求反向代理到另一台服务器。

总而言之,如果 URL 包含字符串“api”,那么我希望请求在其他地方反向代理。

我可以看到 Twisted 有一个 built in Reverse Proxy,但我不知道如何使用它,以便我可以过滤以这样一种方式发出的请求,即一些请求会被发送到备用服务器,而另一些则不会.

【问题讨论】:

    标签: python python-3.x twisted reverse-proxy


    【解决方案1】:

    ReverseProxyResource 是一种资源。您可以将其放入资源层次结构中。

    root = Resource()
    root.putChild("something.html", SomethingHTML())
    root.putChild("api", ReverseProxyResource(...))
    

    这只是资源层次结构的一个示例。您可以通过IResource 支持的任何方式将ReverseProxyResource 与其他资源组合。

    【讨论】:

      猜你喜欢
      • 2013-04-23
      • 1970-01-01
      • 2018-09-10
      • 2019-07-15
      • 2020-04-19
      • 2013-04-02
      • 2020-04-14
      • 1970-01-01
      • 2013-05-22
      相关资源
      最近更新 更多