无法访问在GCE上以0.0.0.0运行的Flask应用 [英] Can't access Flask app running on 0.0.0.0 on GCE
问题描述
我在主机"0.0.0.0"和端口7000上为本地Google计算实例设置了防火墙规则.
I set Firewall Rule for my local google compute instance at host '0.0.0.0' and port 7000.
我执行了python server.py
,它在https://0.0.0.0:7000
上运行
但是当我在本地浏览器上输入https://external-ip: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.
那么如何在Google计算引擎上运行flask并在本地计算机浏览器中打开?
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')
推荐答案
几件事:
检查您的VPC防火墙:
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.
如果您使用的是https,则可能需要以下内容:
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)
最后,它是https://而不是\
Lastly, it's https:// not \
这篇关于无法访问在GCE上以0.0.0.0运行的Flask应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!