尝试使用gunicorn和nginx设置django,从nginx获取一些奇怪的错误:
2015/10/07 06:17:22 [error] 28817#0: *12 connect() to
unix:/home/david/StockSearch/stocksearch/stocksearch.sock failed (111: Connection refused) while connecting to upstream,
client:79.176.114.181, server: 128.199.36.78, request: "GET / HTTP/1.1",
upstream: "http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock:/",
host: "128.199.36.78" 2015/10/07 06:17:24 [error] 28817#0: *12 recv()
failed (104: Connection reset by peer) while reading response header from upstream,
client: 79.176.114.181, server: 128.199.36.78, request: "GET / HTTP/1.1",
upstream: "http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock:/",
host: "128.199.36.78"
nginx config:
server {
listen 80;
server_name 128.199.36.78;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/david/StockSearch/stocksearch;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock;
}
}
gunicorn配置:
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid david
setgid www-data
chdir /home/david/StockSearch/stocksearch
exec /home/david/Env/ssenv/bin/gunicorn --workers 3 --bind unix:/home/david/StockSearch/stocksearch/stocksearch.sock stocksearch.wsgi:application
答案 0 :(得分:0)
我对nginx和gunicorn很新,但我认为你不能这样做:
proxy_pass http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock;
这是使用fastCGI而不是使用proxypass:
include fastcgi_params;
fastcgi_pass unix:/var/run/php5-fpm.sock;
astcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$
我可以告诉我如何在我的服务器中配置我的nginx和gunicorn,我希望我的配置有所帮助:
server {
server_name XX.XX.XX.XX;
access_log /webapps/Project/log/acces.log;
error_log /webapps/Project/log/error.log warn;
location /static/ {
root /webapps/Project;
}
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM N$
}
}
然后我在我的本地机器上启动我的gunicorn服务器,如:
gunicorn Project.wsgi:application --bind 127.0.0.1:8001