4
votes

I have a google cloud compute engine instance with Ubuntu 16.04 on it. I have a flask app running on port 5000.

I've set up firewall rules to allow ingress traffic for any host (using 0.0.0.0/0 filter) for tcp:5000. I ran the

sudo ufw allow 5000

command on the console.

At this point I was expecting to see the flask app by entering http://external_ip:5000 on my browser. But that is not the case. I get "external_ip refused to connect." error on the browser. What am I doing wrong?

Its working if I run the flask app on port 80 though.

As the allow-internal rule is active in the firewall rules. I thought maybe try accessing from a node under the same project (thus same default network). But no luck.

1
Verify port 5000 is in listening state on the VM instance using 'netstat -plant' and using 'nmap <external-ip-vm-instance>' and is associated with the flask application when running. In addition, verify the firewall rule you created to allow ingress traffic for any host is applicable to the instance hosting flask application. You can also check this thread as a reference.N Singh

1 Answers

2
votes

I had the same problem. The way to fix is, to add host parameter to Flask app as shown below. By default Flask App is designed to work on localhost only. This has fixed the problem for me

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