【问题标题】:Accessing localhost externally?从外部访问本地主机?
【发布时间】:2016-08-04 17:26:34
【问题描述】:

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

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

【问题讨论】:

    标签: django localhost static-ip-address


    【解决方案1】:

    您需要在0.0.0.0:8000 上运行您的网络服务器,然后在外部您将使用 ip 或主机名进行访问。使用0.0.0.0 意味着django 服务会监听所有配置的网络接口。

    查看wikipedia 了解有关 0.0.0.0 的详细信息。

    另一个关于 serverfault 的 answer 可能会有所帮助。

    【讨论】:

    猜你喜欢
    • 2016-06-09
    • 2012-04-07
    • 2021-07-16
    • 1970-01-01
    • 2015-06-06
    • 2011-02-12
    • 1970-01-01
    • 2020-03-27
    相关资源
    最近更新 更多