3

I am running a very simple http server on a VM in GCE.

The code is very simple

from flask import Flask, render_template, request, json, abort

app = Flask(__name__)
@app.route('/', methods=['GET'])
def heartbeat():
  return 'hello'

if __name__ == '__main__':
  app.run(host='0.0.0.0')

I can reach the '/' on the server using lynx locally

enter image description here

I did not modify any firewall rules. Here is part of the rules:

enter image description here

Here is part of the VM information that is relevant to the networking

enter image description here

You can see http traffic is allowed.

However when I tried to connect to the server from my PC, the connection t

Anthony Kong
  • 3,288
  • 11
  • 57
  • 96

3 Answers3

5

By default python flask is listening to port 5000. I need a firewall rule to allow the traffic to go through

enter image description here

Anthony Kong
  • 3,288
  • 11
  • 57
  • 96
  • That's correct. I ran into same problem and found the firewall in my PC is blocking 5000 outgoing - another thing that worth to check! – Deqing Nov 28 '17 at 04:56
3

You need to create a firewall rule that allows traffic to that port. In the google cloud console on your browser go to Menu -> VPC Network -> Firewall Rules. Here is a template of the rule you should create. This rule allows any traffic on any of your ports.

enter image description here

-1

You can also run your app on port 80 by slightly changing your last line to:

app.run(host='0.0.0.0', port=80)
Alex Palcuie
  • 274
  • 1
  • 4
  • It's suggested that [not to use port 80 for flask app](https://stackoverflow.com/questions/33086555/why-shouldnt-flask-be-deployed-with-the-built-in-server) – Deqing Nov 28 '17 at 03:59