【发布时间】:2015-03-30 12:10:08
【问题描述】:
将gunicorn监听地址绑定到我的nginx服务器时遇到错误,事情是这样的:
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
}
}
}
当我运行gunicorn -c gunicorn-wsgi.py myproject.wsgi 时,出现错误:
[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)
我注意到 gunicorn 提到如果您在与 gunicorn 不同的主机上运行 nginx,您需要告诉 gunicorn 信任 nginx 发送的 x-forward-* 标头。
如果您在与 Gunicorn 不同的主机上运行 Nginx,则需要 告诉 Gunicorn 信任 Nginx 发送的 X-Forwarded-* 标头。经过 默认情况下,Gunicorn 将仅在连接时信任这些标头 来自本地主机。这是为了防止恶意客户端 伪造这些标题:
gunicorn -w 3 --forwarded-allow-ips="10.170.3.217,10.170.3.220" test:app
我按照它所说的,但仍然是同样的错误。我将地址更改为 127.0.0.1 和 0.0.0.0 ,它们工作正常,但不安全,如何配置,请帮助我!
【问题讨论】: