英文:
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
答案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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论