[英]Why can I connect to http://127.0.0.1:8000/ but not to http://192.168.1.6/
I'm running OS X Mountain Lion on a machine with local IP address 192.168.1.6 (as reported by both the Network utility and ifconfig) and am running a local (Django) development web server on port 8000 that I would like to connect to from a virtual machine running a guest OS on the same machine.我在本地 IP 地址为 192.168.1.6 的机器上运行 OS X Mountain Lion(由 Network 实用程序和 ifconfig 报告),并且在我想连接的端口 8000 上运行本地(Django)开发 Web 服务器从在同一台机器上运行来宾操作系统的虚拟机。
On the host OS (ie, OS X running on the metal of the machine w/ address 192.168.1.6) I can connect to my test web server through the browser by navigating to 127.0.0.1:8000;在主机操作系统(即运行在地址为 192.168.1.6 的机器上的 OS X)上,我可以通过浏览器导航到 127.0.0.1:8000 连接到我的测试 Web 服务器; or localhost:8000;
或本地主机:8000; but not when using the machine's local IP address.
但在使用机器的本地 IP 地址时则不然。 Here's what makes this extra confusing:
这是什么让这个额外的混乱:
Here are the ipfw rules:以下是 ipfw 规则:
00100 allow tcp from any to any dst-port 8000
65535 allow ip from any to any
Here is additional confirmation that the port is, indeed, being listened to by my test server:这是我的测试服务器确实正在侦听端口的额外确认:
netstat -an | grep 8000
tcp4 0 0 127.0.0.1.8000 *.* LISTEN
so what's going on here?那么这里发生了什么? Somehow port 22 is being treated differently than port 8000, but every place I can think to look for those differences I can't find any.
不知何故,端口 22 的处理方式与端口 8000 不同,但我能想到的每个地方都找不到这些差异。 Why can't I get into this machine's port 8000 using its local ip address?
为什么我不能使用它的本地IP地址进入这台机器的8000端口?
When you start Django development server you need to give the address explicitly:当你启动 Django 开发服务器时,你需要明确给出地址:
python manage.py runserver 192.168.1.6:8000
Or if you want the server to run on all interfaces you can use:或者,如果您希望服务器在所有接口上运行,您可以使用:
python manage.py runserver 0.0.0.0:8000
In other case Django development server defaults to running on the local interface only.在其他情况下,Django 开发服务器默认仅在本地界面上运行。
The problem for me was I accidentally quit the server whenever trying to copy the server address.对我来说,问题是我在尝试复制服务器地址时不小心退出了服务器。 So instead of using
ctrl+C
just write down the address into your browser.因此,不要使用
ctrl+C
只需在浏览器中记下地址即可。
I solved the issue.There are a few things you might be missing.Listing them below-我解决了这个问题。你可能会遗漏一些东西。在下面列出它们-
1.Once it starts the server, do not press Ctrl+C anyhow .u might be pressing it to copy to url and that accidently closes the server due to which it might be happening. 1.一旦它启动服务器,无论如何都不要按Ctrl + C。你可能正在按它来复制到url,并且由于它可能会发生意外关闭服务器。
2.instead of http://127.0.0.1:8000/ ...change the port number to http://127.0.0.1:8080/ ...That would work. 2.代替http://127.0.0.1:8000/ ...将端口号更改为http://127.0.0.1:8080/ ...那会起作用。
3.Try changing the firewall setting and allow the app. 3.尝试更改防火墙设置并允许该应用程序。
4.Try opening it with different browsers and incognito too. 4.尝试使用不同的浏览器和隐身模式打开它。
The above steps helped solve my issue.Hope they help u too...:)以上步骤帮助解决了我的问题。希望它们也能帮助你...:)
请不要通过ctr + C快捷键复制地址,因为它会关闭服务器。请右键单击复制相同的地址,或者自己写一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.