Can't access Flask app running on 0.0.0.0 on GCE

家住魔仙堡 提交于 2019-12-24 10:01:01

问题


I set Firewall Rule for my local google compute instance at host '0.0.0.0' and port 7000.

And I executed python server.py, it was running on https://0.0.0.0:7000 but when I enter https://external-ip:7000 on my local browser it did not work.

So how can I run flask on google compute engine and open in my local computer browser?

server.py

from flask import Flask
app = Flask(__name__)

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

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

回答1:


A few things:

Check your VPC firewall:

https://cloud.google.com/vpc/docs/firewalls

In your terminal, see if connections are working locally on that host by issuing:

telnet localhost 7000

If it connects then it's either firewall or the below.

If you're running on https, you'll probably need to have something along the lines of:

context = ('host.crt', 'host.key')
app.run(host='0.0.0.0',port='7000', ssl_context=context)

Lastly, it's https:// not \



来源:https://stackoverflow.com/questions/49414776/cant-access-flask-app-running-on-0-0-0-0-on-gce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!