gunicorn on heruko binding to localhost, without m

2019-07-28 01:39发布

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?)

1条回答
放荡不羁爱自由
2楼-- · 2019-07-28 02:14

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

查看更多
登录 后发表回答