Reputation: 829
I encounterd an error when bound gunicorn listen address to my nginx server,here is the thing:
1.gunicorn_wsgi.py
import multiprocessing
bind="192.168.239.145:8080"(my nginx server ip address)
workers = multiprocessing.cpu_count() 2 + 1
2.nginx.conf
http{
upstream realservers{
server 192.168.239.146:8080;(my django and gunicorn address)
}
servr{
listen 80;
server_name example.com
location / {
proxy_pass http://realservers
}
}
}
when i ran gunicorn -c gunicorn-wsgi.py myproject.wsgi
,error occur:
[2015-03-30 04:56:05 -0700] [38656] [INFO] Starting gunicorn 19.3.0
[2015-03-30 04:56:05 -0700] [38656] [ERROR] Invalid address: ('192.168.239.145', 8080)
I noticed that gunicorn has mentioned that if you are running nginx on a different host than gunicorn you need to tell gunicorn to trust the the x-forward-* headers sent by nginx.
If you are running Nginx on a different host than Gunicorn you need to tell Gunicorn to trust the X-Forwarded-* headers sent by Nginx. By default, Gunicorn will only trust these headers if the connection comes from localhost. This is to prevent a malicious client from forging these headers:
gunicorn -w 3 --forwarded-allow-ips="10.170.3.217,10.170.3.220" test:app
I followed what it said ,but still same error. And I change the address to 127.0.0.1 and 0.0.0.0 ,they work fine,but is not secure,How to configure it ,please help me !
Upvotes: 3
Views: 6449
Reputation: 599450
It's obviously not your problem, but it is confusing that you're calling your configuration file "gunicon_wsgi.py". It's not your WSGI file. Call it "gunicorn_conf.py" or something similar.
Your problem is however that you have misunderstood what it means to bind to an IP address. You can't bind your gunicorn server to an IP address on a different machine; that makes no sense at all. And it's not "insecure" to bind to 0.0.0.0.
Upvotes: 3