Python3 Twisted反向代理重定向错误。

huangapple go评论131阅读模式
英文:

Python3 Twisted Reverse Proxy Redirecting Incorrectly

问题

我正在尝试使用Twisted制作反向代理然而当我尝试添加一个子资源时我遇到了一些意外的行为

从我的理解来看程序应该将"127.0.0.1/app1:8090"重定向到youtube.com然而它只是重定向到"https://127.0.0.1/app1:8090"然后在我的浏览器中显示"无法连接"错误

即使我将site1转换为Site也无法解决这个问题

```site1 = Site(proxy.ReverseProxyResource('youtube.com', 80, b''))```

将b''替换为b'/'也不能解决这个问题
我怀疑问题可能是浏览器根本找不到资源这就是为什么它尝试找到https版本但仍然失败的原因例如在浏览器中尝试连接到192.168.1.132什么都没有会重定向到https://192...然后告诉我有问题

任何帮助或指导将不胜感激 :)
英文:

I am trying to make a reverse proxy with Twisted. However, I get some unexpected behaviour when I try adding a child resource.

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('youtube.com', 80, b'')
site2 = proxy.ReverseProxyResource('yahoo.com', 80, b'')

root = Resource()
root.putChild(b"app1", site1)
root.putChild(b"app2", site2)

reactor.listenTCP(8090, Site(root))
reactor.run()

From my understanding, the program should redirect "127.0.0.1/app1:8090" to youtube.com. However, it is simply redirecting to "https://127.0.0.1/app1:8090", which then gives an "Unable to connect" error in my browser.

The problem persists even if I convert site1 to a Site, through:

site1 = Site(proxy.ReverseProxyResource('youtube.com', 80, b''))

Replacing b'' by b'/' also does not solve the issue.
I suspect the issue may be something like the browser cannot even find the resource in the first place - which is why it tries to find the https version but still fails. For example, trying to connect to 192.168.1.132 (nothing there) in my browser redirects to https://192... before telling me there's a problem.

Any help or guidance would be much appreciated Python3 Twisted反向代理重定向错误。

答案1

得分: 1

不确定这是否是拼写错误,但在您的浏览器中,您应该尝试连接到 127.0.0.1:8090/app1 而不是 127.0.0.1/app1:8090(请查看URL中的端口位置)。

英文:

Not sure if that is a typo or not but in your browser you should try to connect to 127.0.0.1:8090/app1 and not 127.0.0.1/app1:8090 (See where the port is in the url)

huangapple
  • 本文由 发表于 2023年7月3日 16:22:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603023.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定