如何使用Gunicorn在GCP上托管Flask应用程序?

时间:2020-06-30 06:12:51

标签: flask google-cloud-platform gunicorn flask-restful apache-superset

我正在尝试在开发模式下使用Gunicorn在GCP上托管我的超集应用。这是我的配置:

应用安装说明:https://superset.incubator.apache.org/installation.html 应用程序配置说明:https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-18-04

请注意,我正在使用以下命令打开端口监听:

sudo ufw allow 8088

要运行该应用程序:

superset run -p 8088 -h 0.0.0.0

我要访问的链接:http:// gcp_external_ip:8088

但它没有响应。

请注意,我已经设置了所有HTTP和https流量: enter image description here

这是我的命令外壳: enter image description here

请让我知道我要去哪里了?我无法从其他系统访问服务器: enter image description here

外部ping也正在发生: enter image description here

3 个答案:

答案 0 :(得分:2)

您无需更改应用程序可以通过Internet公开的端口-如果您对8088表示满意,请使用它。

只需确保您create a GCP firewall rule允许流量进入。默认情况下,HTTP serverHTTPS server分别打开端口80和443。默认情况下,端口8088被阻止。

示例防火墙规则为所有IP中带有“ tag1”标签的实例打开端口8080:

gcloud compute --project=myproject firewall-rules create port8088 --direction=INGRESS --priority=1000 --network=default --action=ALLOW --rules=tcp:8088 --source-ranges=0.0.0.0/0 --target-tags=tag1

还-将“ tag1”标签分配给您要“取消阻止”的VM。

答案 1 :(得分:0)

allow HTTP在GCP VPC防火墙中打开80端口。将flask应用程序的服务端口更改为端口80

答案 2 :(得分:0)

问题在于设置防火墙端口,并通过添加端口允许它们在防火墙设置的HTTP和https中访问。感谢@Guillem的帮助!如果有人遇到此问题,请添加评论,我会尽快与您联系。