开发者社区> 问答> 正文

在ecs上启动flask应用后,无法通过公网ip访问网站

ecs用的是专有网络,确认已开启80和5000端口,地址段是0.0.0.0/0。
ssh进到ecs之后启动flask应用用的默认地址127.0.0.1:5000,也尝试过把端口改成80,通过 服务器公网ip:端口 尝试访问网站均显示无法连接到服务器。请问怎么解决…
(最简单的flask示例,未使用uwsgi或者nginx)
启动flask应用后通过netstat确认80端口在listen状态,仍然无法访问

展开
收起
1792202766802139 2017-08-17 00:47:05 13980 0
3 条回答
写回答
取消 提交回答
  • 我的解决方案:安全组规则里面需要添加端口 5000, 然后就可以了。。。

    2019-07-17 21:30:07
    赞同 展开评论 打赏
  • 我也是遇到同样的问题。。还不知道怎么解决


    目前来看,端口设置正确的话, 可能是flask配置的问题
    启动python自带的HTTP服务器 sudo python -m SimpleHTTPServer 5000 ,这样启的网站可以公网访问
    而使用flask官方网站上的示例启的服务器,公网不能访问
    我的环境是CentOS 7.2 python 2.7 flask是最新版本


    flask默认只能本机访问,要让网络上其他机器访问,需要增加host为0.0.0.0

    flask官网原文(http://flask.pocoo.org/docs/0.12/quickstart/#a-minimal-application)
    Externally Visible Server

    If you run the server you will notice that the server is only accessible from your own computer, not from any other in the network. This is the default because in debugging mode a user of the application can execute arbitrary Python code on your computer.

    If you have the debugger disabled or trust the users on your network, you can make the server publicly available simply by adding --host=0.0.0.0 to the command line:

    flask run --host=0.0.0.0

    This tells your operating system to listen on all public IPs.

    也可以这样:
    app.run(host="0.0.0.0", port=80)

    2019-07-17 21:30:07
    赞同 1 展开评论 打赏
  • 阿里云大学导师

    您好,请问服务器上有测试过是否能正常访问,以及安全组是否放行响应的端口?

    2019-07-17 21:30:07
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
如何运维千台以上游戏云服务器 立即下载
网站/服务器取证 实践与挑战 立即下载
ECS块储存产品全面解析 立即下载