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状态,仍然无法访问
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。
我也是遇到同样的问题。。还不知道怎么解决
目前来看,端口设置正确的话, 可能是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)