2016-04-13 73 views
1

这可能是一个非常基本的问题。我ssh到我的虚拟Ubuntu的服务器,并开始一个Django的web服务器上的本地主机上运行:从外部访问本地主机?

Downloading/unpacking django 
    Downloading Django-1.9.5-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded 
Installing collected packages: django 
Successfully installed django 
Cleaning up... 
Performing system checks... 

System check identified no issues (0 silenced). 

You have unapplied migrations; your app may not work properly until they are applied. 
Run 'python manage.py migrate' to apply them. 

April 13, 2016 - 14:16:19 
Django version 1.9.5, using settings 'mysite.settings' 
Starting development server at http://127.0.0.1:8000/ 
Quit the server with CONTROL-C. 

Ubuntu的服务器有一个静态IP [x.xxx.xxx.xxx]所以从另一个网络上的另一台机器我尝试访问在浏览器上面的网站使用静态IP地址:

x.xxx.xxx.xxx:8000 

,但我得到:

This site can’t be reached 

x.xxx.xxx.xxx refused to connect. 
ERR_CONNECTION_REFUSED 

所以我认为我无法访问的网站是这样,这是只有在主机它可用即使主机有外部/静态IP地址?

编辑:

答案也是: https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server

python manage.py runserver 0.0.0.0:8000 

回答

2

您需要在0.0.0.0:8000运行Web服务器,那么外部你可以使用IP或主机名来访问。使用0.0.0.0意味着django服务将监听所有配置的网络接口。

检查wikipedia关于0.0.0.0的详细信息。

serverfault上的另一个answer会对您有所帮助。

+0

你的意思是0.0.0.0:8000?请参阅https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server – u123

+0

对不起,错了。 –