1

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?

xbello
  • 7,223
  • 3
  • 28
  • 41
reticentroot
  • 3,612
  • 2
  • 22
  • 39
  • manage.py is django .... – Joran Beasley Oct 22 '15 at 21:36
  • No it's isn't lol, yes django has a manage.py file, but one can easily be written in flask using flask-script – reticentroot Oct 22 '15 at 21:38
  • 2
    Bit of a guess - but you could try getting Gunicorn to listen on `0.0.0.0` (i.e. all network interfaces) to see if that works. – bunnmatt Oct 22 '15 at 22:01
  • `python manage.py runserver` is explicitly a django thing ... yes you can write your own file that mimics it for flask, but it doesnt make alot of sense to do so, but all of that is really aside from your question ... but as it stands this question is not going to be answerable other than the comment above mine ... – Joran Beasley Oct 22 '15 at 22:06
  • https://flask-script.readthedocs.org/en/latest/ when you look at most large scale flask apps, some sort of manager file is implemented, so I disagree with your statement and would appreciate any help on my particular problem, since I did not make the post to argue which framework had a manage.py file. I would say take a look on git and you'll see it is a common idiom in flask. – reticentroot Oct 22 '15 at 22:19
  • @bunnmatt that was totally it, I guess my localhost wasn't the same, go figure. Thanks, you make it an answer and I'll accept. – reticentroot Oct 22 '15 at 22:32

1 Answers1

3

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.

Community
  • 1
  • 1
bunnmatt
  • 797
  • 10
  • 23