问题
I've been following the tutorial on https://devcenter.heroku.com/articles/django#declare-process-types-with-procfile. It went smoothly except for one thing that bothers me.
After starting foreman I should see the following:
$ foreman start
2013-04-03 16:11:22 [8469] [INFO] Starting gunicorn 0.17.2
2013-04-03 16:11:22 [8469] [INFO] Listening at: http://127.0.0.1:8000 (8469)
However, I get:
Starting gunicorn 17.5
Listening at: http://0.0.0.0:5000
How can I change it so that it listens only to my local machine (ie. 127.0.0.1)?
My Procfile contains only
web: gunicorn hellodjango.wsgi
thanks!
回答1:
This looks to be the default IP address used when you run use gunicorn to serve a WSGI app with foreman.
Running your django app without foreman like this:
gunicorn hellodjango.wsgi:application
Will bind it to gunicorn's default, 127.0.0.1:8000
2013-08-23 00:02:54 [45352] [INFO] Starting gunicorn 17.5
2013-08-23 00:02:54 [45352] [INFO] Listening at: http://127.0.0.1:8000 (45352)
2013-08-23 00:02:54 [45352] [INFO] Using worker: sync
2013-08-23 00:02:54 [45355] [INFO] Booting worker with pid: 45355
And specifying in your Procfile
which binding to use:
web: gunicorn -b 127.0.0.1:8000 hellodjango.wsgi
Will bind it to 127.0.0.1:8000
, or whatever you specify.
00:06:26 web.1 | started with pid 45384
00:06:26 web.1 | 2013-08-23 00:06:26 [45384] [INFO] Starting gunicorn 17.5
00:06:26 web.1 | 2013-08-23 00:06:26 [45384] [INFO] Listening at: http://127.0.0.1:8000 (45384)
00:06:26 web.1 | 2013-08-23 00:06:26 [45384] [INFO] Using worker: sync
00:06:26 web.1 | 2013-08-23 00:06:26 [45387] [INFO] Booting worker with pid: 45387
I'd be interested to find exactly where foreman tells gunicorn to use 0.0.0.0
as a default.
来源:https://stackoverflow.com/questions/18374878/gunicorn-on-heroku-binding-to-localhost