Flask - 如何通过路由器使应用程序在外部可见?

Flask - How to make an app externally visible through a router?

简答题

你如何运行一个简单的基于 Flask 的网站在互联网上可见,从一台正在访问互联网的主机 从无线路由器?

问题详情

我想根据 Quickstart Guide.

使 Flask 应用程序在 Internet 上可见

如果我在下面启动简单的 Flask 应用程序,它就可以从与主机位于同一网络上的计算机访问,但不能从通过另一个网络通过互联网连接的设备访问。

问题与 here and here, with the added element that running from a home pc seems to suggest that external connections point to the xx port of the router, not to the xx port of the host pc, as is suggested in the comments in this post 中讨论的问题类似。

我做了什么

参考下面的代码,这是我所做的:

结果是"The webpage is not available"。

有人遇到过同样的问题吗?这是路由器问题吗?

参考 Flask 应用程序

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

if __name__ == '__main__':
    app.run(host= '0.0.0.0', port=9000, debug=False)

基本设置是创建一条规则,将请求转发到端口 80 and/or 端口 443 到本地网络中的目标主机。

示例创建 NAT(地址转换)和端口转发规则以将入站 HTTP/S 请求转发到您的本地网络主机 运行 您的 python 应用程序。

例如:

app.run(host= '192.168.0.58', port=9000, debug=False)

您的 NAT 规则应以端口 9000 上的 192.168.0.58 为目标。