Reputation: 3682
I'm trying to run my flask app with gunicorn on my Raspberry pi. I've set up my router to port forward the localhost:5000
. This works well when I run my flask app via python manage.py runserver
. I can use my browser from any device and type http://**.**.***.***:5000/
and it will load my flask application. However when I try and run the app via gunicorn I receive an error connecting page. I run the the gunicorn exactly like the flask documentation says to. If I check gunicorn's logs I can see the html being rendered. Here's the kicker, when I run the app with gunicorn locally (gunicorn -w 2 -b localhost:5000 my_app:app
), it works just fine. I have optimum online, my router setting are as followed...
protocol -> all
port -> 5000
forward port to -> same as incoming port
host -> raspberrypi
locate device by -> ipaddress
Like I said these settings work just fine from my pi when I use python's built in wsgi server. Gunicorn works just fine on when I run it locally and I can see my app when I type localhost:5000
in the browser, it's just when I set it up on my pi and try to access the page with the external IP, if I don't use gunicorn the external IP works just fine. I can't figure it out. Any ideas?
Upvotes: 1
Views: 3185
Reputation: 817
You need to have Gunicorn listen on 0.0.0.0
(all network interfaces). This then means it will be listening on an externally accessible IP address.
There is more information on the difference between localhost
and 0.0.0.0
in this post on ServerFault.
Upvotes: 3