在Django中关于IP 0.0.0.0 [英] About IP 0.0.0.0 in Django

查看:539
本文介绍了在Django中关于IP 0.0.0.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一台服务器,我们运行着一个Django网站。由于我们要测试网站,我们正在使用Django的内置开发服务器(即 runserver )。但是我对以下命令的ip感到好奇:

  python manage.py runserver 0.0.0.0:80 

它导致运行中的网站,我们可以远程使用服务器的ip访问。

但是当使用 127.0.0.1 代替:

  python manage.py runserver 127.0.0.1 :80 

没有人可以使用其他电脑上的服务器的ip访问该网站。



那么为什么?什么是 0.0.0.0 完全意味着(Google说这是默认路线)?为什么不能远程访问 127.0.0.1:80

解决方案

0.0.0.0:80是一个快捷方式,意思是绑定到本计算机支持的所有IP地址。 127.0.0.1:80使它仅绑定到lo或loopback界面。如果您只有一个仅具有一个IP地址的 NIC ,则可以明确地绑定到它,说,192.168.1.1:80(如果192.168.1.1是您的IP地址),或者您可以列出计算机响应的所有IP,但0.0.0.0:80是该快捷方式。


We've got a server over which we're running a Django powered site. Since we want to test the site, we're using Django's build-in development server (i.e runserver). But I'm curious about the ip of the following command:

python manage.py runserver 0.0.0.0:80

It results in a running site we can visit using server's ip remotely.
But when using 127.0.0.1 instead:

python manage.py runserver 127.0.0.1:80

No one can visit the site with the sever's ip from another pc.

So why? What does 0.0.0.0 exactly means (Google says it's the default route) ? Why can't 127.0.0.1:80 be accessed remotely?

解决方案

0.0.0.0:80 is a shortcut meaning "bind to all IP addresses this computer supports". 127.0.0.1:80 makes it bind only to the "lo" or "loopback" interface. If you have just one NIC with just one IP address, you could bind to it explicitly with, say, "192.168.1.1:80" (if 192.168.1.1 was your IP address), or you could list all the IPs your computer responds to, but 0.0.0.0:80 is a shortcut for that.

这篇关于在Django中关于IP 0.0.0.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆