Flask服务器从我的公共IP地址不可见 [英] Flask server not visible from my public ip address
问题描述
- 设置一个静态IP地址:192.168.1.11( http://i.imgur.com/Z9GEBYV.png )
- 转发路由器上的端口33到我的静态IP地址( http://i.imgur.com/KGNQ2Qk.png ) / li>
- 安装烧瓶以使用我的静态IP和端口:33
我正在使用以下代码作为测试web服务器
from flask import烧瓶,请求,重定向
app =烧瓶(__ name__)
@ app.route(/)
def hello_world():
返回Test 123
if __name__ ==__main__:
app.run(host =0.0.0.0,port =33)
我打开我的浏览器: http://192.168.1.11:33/ 页面显示正常,我看到测试123
尝试连接时出现问题当我打开我的浏览器到 http: //xx.xxx.xxx.xx:30 (我的IP地址),我看到的只是本网站无法访问,xx.xxx.xxx.xx拒绝连接
我查找了所有的堆栈溢出答案,我做了以下操作:
显示的代码运行和错误截图: http ://i.imgur.com/a05GvEs.png
我的问题是:我需要做些什么来使我的烧瓶服务器可以从我的公共IP地址吗?
?如果是,你看到你的主机为192.168.1.11那里?
你必须在主机上使用'0.0.0.0',告诉Flask听在所有的地址。
尝试用引号指定端口为 app.run(host =0.0.0.0,port =33)
I'm trying to run a flask server on my desktop PC that is publicly available on the internet. I've done the following:
- Set up a static IP address: 192.168.1.11 (http://i.imgur.com/Z9GEBYV.png)
- Forwarded port 33 on my router to my static ip address (http://i.imgur.com/KGNQ2Qk.png)
- Setup flask to use my static ip and port: 33
I'm using the following code as a test webserver
from flask import Flask, request, redirect
app = Flask(__name__)
@app.route("/")
def hello_world():
return "Test 123 "
if __name__ == "__main__":
app.run(host="0.0.0.0", port="33")
When I open my browser to: http://192.168.1.11:33/ the page displays properly, I see "Test 123"
My problem comes when trying to connect to my webserver from my public ip address When I open my browser to http://xx.xxx.xxx.xx:30 (my ip address) all I see is "this site can't be reached, xx.xxx.xxx.xx refused to connect"
I've looked up all the stack overflow answers, I've done the following:
- Turned off windows firewall
- Changed host from "192.168.1.11" to "0.0.0.0"
- Tried a different port
screenshot of code running and error shown: http://i.imgur.com/a05GvEs.png
My question is: What do I need to do to make my flask server visible from my public ip address?
Do you have DHCP activated on your router? If yes do you see your host as 192.168.1.11 in there?
You have to use '0.0.0.0' on host, that tells Flask to listen on all addresses.
Try specifying the port with quotes as app.run(host="0.0.0.0", port="33")
这篇关于Flask服务器从我的公共IP地址不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!