Flask服务器从我的公共IP地址不可见 [英] Flask server not visible from my public ip address

查看:387
本文介绍了Flask服务器从我的公共IP地址不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的台式电脑上运行一个在互联网上公开的烧瓶服务器。我已经做了以下:



我正在使用以下代码作为测试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拒绝连接



我查找了所有的堆栈溢出答案,我做了以下操作:


  • 打开关闭Windows防火墙
  • 将主机从192.168.1.11更改为0.0.0.0
  • 尝试了不同的端口


显示的代码运行和错误截图: 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:

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屋!

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