从外部访问localhost? [英] Accessing localhost externally?

查看:183
本文介绍了从外部访问localhost?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常基本的问题。我SSH到我的虚拟Ubuntu服务器,并启动在localhost上运行的django网络服务器:

 下载/解包django 
下载Django -1.9.5-py2.py3-none-any.whl(6.6MB):6.6MB下载
安装收集的软件包:django
成功安装django
清理...
执行系统检查...

系统检查已识别无问题(0沉默)。

您有未应用的迁移;您的应用程序在应用之前可能无法正常工作。
运行'python manage.py migrate'来应用它们。

2016年4月13日 - 14:16:19
Django版本1.9.5,使用设置'mysite.settings'
启动开发服务器http://127.0.0.1 :8000 /
使用CONTROL-C退出服务器。

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

  x.xxx.xxx.xxx: 8000 

但是我得到:

 此网站无法访问

x.xxx.xxx.xxx拒绝连接。
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 


解决方案

您需要在 0.0.0.0:8000 上运行您的Web服务器,然后从外部使用ip或主机名来访问。使用 0.0.0.0 表示django服务将侦听所有配置的网络接口。



检查维基百科关于0.0.0.0的详细信息。



另一个答案对serverfault可能会有帮助。


This is probably a very basic question. I SSH to my virtual Ubuntu server and start a django webserver running on localhost:

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.

The Ubuntu server has a static IP [x.xxx.xxx.xxx] so from another machine on another network I try to access the above website in a browser using that static IP address:

x.xxx.xxx.xxx:8000

But I get:

This site can’t be reached

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

So I assume that I cannot access the website like this and that is only available on the host it self even though the host has an external/static IP address?

Edit:

The answer is also in: https://docs.djangoproject.com/en/1.9/intro/tutorial01/#the-development-server

python manage.py runserver 0.0.0.0:8000

解决方案

You need to run your web server on 0.0.0.0:8000, then externally you would use either ip or host name to access. Using 0.0.0.0 means the django service would listen to all configured network interfaces.

Check wikipedia on details about 0.0.0.0.

Another answer on serverfault could be helpful.

这篇关于从外部访问localhost?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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