简体   繁体   English

无法访问GCE上0.0.0.0上运行的Flask应用

[英]Can't access Flask app running on 0.0.0.0 on GCE

I set Firewall Rule for my local google compute instance at host '0.0.0.0' and port 7000. 我在主机'0.0.0.0'和端口7000上为我的本地google计算实例设置了防火墙规则。

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. 我执行了python server.py ,它运行在https://0.0.0.0:7000但是当我在本地浏览器上输入https://external-ip:7000时它无效。

So how can I run flask on google compute engine and open in my local computer browser? 那么如何在谷歌计算引擎上运行烧瓶并在我的本地计算机浏览器中打开?

server.py 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')

A few things: 一些东西:

Check your VPC firewall: 检查您的VPC防火墙:

https://cloud.google.com/vpc/docs/firewalls 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: 如果你在https上运行,你可能需要有以下几点:

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

Lastly, it's https:// not \\ 最后,它是https://不是\\

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM