简体   繁体   中英

Django gunicorn nginx “connection reset by peer while reading response header”

trying to set up django with gunicorn and nginx, getting some weird errors from 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 config:

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

I'm very new to nginx and gunicorn, but i think you can't do that:

proxy_pass http://unix:/home/david/StockSearch/stocksearch/stocksearch.sock;

this is achived with fastCGI not with proxypass:

include fastcgi_params;
fastcgi_pass   unix:/var/run/php5-fpm.sock;
astcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_nam$

I can tell how i configure my nginx and gunicorn in my server, i hope my configuration helps:

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$
    }
}

then i start my gunicorn server in my local machine like:

gunicorn Project.wsgi:application --bind 127.0.0.1:8001

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM