1

This is a spin off question from gunicorn on heroku: binding to localhost.

How can I get gunicorn to work both locally (using foreman) and for deployment on Heroku?

Procfile contains:

web: gunicorn mysite.wsgi

When I deploy locally using foreman, gunicorn binds to http://0.0.0.0:5000. I want it to bind to 127.0.0.1:8000. However, if I change to the Procfile to this:

web: gunicorn -b 127.0.0.1:8000 mysite.wsgi

Then I can't deploy to Heroku, the browser will return "application error"

$ heroku ps
=== web (1X): `gunicorn -b 127.0.0.1:8000 mysite.wsgi`
web.1: crashed 2013/08/22 23:45:04 (~ 1m ago)

Where is the default binding address set and/or what gunicorn options do I put in Procfile to get it to work on 127.0.0.1? What could be unique to my situation that causes a deviant default setup (I'm working in mac OS - lion, maybe?)

Community
  • 1
  • 1
Hamlet
  • 63
  • 1
  • 5

1 Answers1

0

Dont bind gunicorn to the local ip with. web: gunicorn -b 127.0.0.1:8000 mysite.wsgi in your procfile. This forces your django app to always use this local port whether or not its deployed locally or on Heroku's servers.

Using

web: gunicorn mysite.wsgi

in your procfile will make your application deploy at 127.0.0.1:8000 locally and 0.0.0.0:5000 on heroku's severs. I know you had to use the bind method in your previous question to get heroku to work locally, but that method is only covering an issue that isn't resolved.

Using foreman start with web: gunicorn mysite.wsgi should work, as told by the official docs (and my own experince :)).

Try just web: gunicorn mysite.wsgi in your procfile, deploy it to heroku and see if it works.

https://devcenter.heroku.com/articles/python

agconti
  • 17,780
  • 15
  • 80
  • 114
  • 2
    Thanks for the quick reply again. I've already reverted to that version of the Procfile, which works and has allowed me to continue working. But then when running locally, I have to point the browser to 0.0.0.0:5000 which just feels wrong. So I'm back to the original problem, which as you say, has an underlying issue that still needs to be resolved. – Hamlet Aug 25 '13 at 23:43
  • +1 for going back. So you followed along with the docs exactly and got that issue? Is there anything in your mysite app the specifies the port to launch on? (im guessing not). It might be worth it to run though the heroku example again, or make a really simple test project to see if you still get the same strange behavior. – agconti Aug 25 '13 at 23:48
  • It really is the simplest possible project. One of the first steps in the hellodjango tutorial (https://devcenter.heroku.com/articles/django#declare-process-types-with-procfile). No, the tutorial doesn't ask you to specify the port, and the example screenshot shows that it should bind to localhost, not 0.0.0.0. – Hamlet Sep 02 '13 at 22:35
  • @Hamlet Yeah, I had the same issue. I'm going to get back to it this week. I'll let you know. – agconti Sep 03 '13 at 00:04
  • anyone find a solution for this? exact same issue – lollercoaster Aug 07 '15 at 14:55
  • @lollercoaster I'm not really sure why you would need to bind your app to local host, but you can get it running with this: `web: gunicorn --pythonpath="$PWD/you_app_name" wsgi:application` – agconti Aug 07 '15 at 15:39