[英]How do I access a python http server from a remote connection?
I'm trying out the command python http.server from the command line, and am trying to access the server. 我正在从命令行尝试命令python http.server,我正在尝试访问服务器。 I can access easily from localhost, but whenever I try to use a remote connection, I am unable to connect. 我可以从localhost轻松访问,但每当我尝试使用远程连接时,我都无法连接。
I've tried different ports, and it doesn't look like my firewall is blocking any connections. 我尝试过不同的端口,看起来我的防火墙不会阻止任何连接。
From the command line, I run 从命令行,我运行
python3 -m http.server 8000
which returns 返回
Serving HTTP on 0.0.0.0 port 8000 ...
However, I can only connect to the server from localhost. 但是,我只能从localhost连接到服务器。
sudo iptables -S
returns the following: 返回以下内容:
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
I expect to be able to connect from a remote host with the url http://10.247.30.125:8000 (my ip address), but I am unable to do so. 我希望能够通过网址http://10.247.30.125:8000 (我的IP地址)从远程主机连接,但我无法这样做。 The same url works fine on localhost. 同一个url在localhost上运行正常。
url中缺少端口尝试此URL它应该工作“ http://10.247.30.125:8000 ”
I figured out what was going on. 我弄清楚发生了什么。 Did some reading about IP and NAT, and noticed that any ip address beginning with a 10 is reserved for private ip addresses. 做了一些关于IP和NAT的阅读,并注意到任何以10开头的ip地址都是为私有IP地址保留的。 So, trying to connect to 10.247.30.125:8000 from anywhere other than my own network (so while not connected to my wifi) doesn't work. 所以,尝试从我自己的网络以外的任何地方连接到10.247.30.125:8000(所以虽然没有连接到我的wifi)不起作用。 To be able to connect from an external network, I would need to set up port forwarding (like Reedinationer suggested), and I would need to use my router's public IP address rather than my computer's private IP address. 为了能够从外部网络连接,我需要设置端口转发(如建议的Reedinationer),我需要使用我的路由器的公共IP地址而不是我的计算机的私有IP地址。 I would set up a port forward from my router to direct external traffic to my computer, which would allow me to connect to my personal computer from an external network. 我会从路由器向前设置一个端口,将外部流量引导到我的计算机,这样我就可以从外部网络连接到我的个人计算机。
Thanks to everyone who responded! 感谢大家的回应!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.