Question

recv() failed (104: Connection reset by peer) error, gunicorn and nginx and Django

Hi, I am getting the recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 105.178.36.13, server: 188.166.61.158, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: "188.166.61.158 while connecting to my site via the IP address. The nginx error log is printing the above error msg. I am deploying a Django site using nginx and gunicorn. I followed this tutorial here: [https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-ubuntu-14-04]

I have tried all possible suggestion on stackoverflow, including increasing the keep alive directive in nginx.conf file, client and header buffer sizes but all seems like non is working.

The interesting thing is that when I run gunicorn in the command line it starts and I connect to the site successfully but when I try to run it from the upstart script, I get the above error. I am out of ideas how to fix this.

any directions are highly welcome.


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

@kamstan6 I think you need to set the environment variable SECRET_KEY into the project, since it won’t have access to OS variables, when being executed with upstart. http://stackoverflow.com/questions/30769075/secret-key-error-with-django-using-uwsgi

Hi @kamstan6

Have you checked if upstart script does exactly the same as your command line? You can find all upstart stuff in /etc/init/ and /etc/init.d/ Sounds to me that it might have something to do with port numbers or maybe the PID file.

Since you’re having problems directly with Gunicorn, then focus on that. It’s not a problem in Nginx until you’re successfully running Gunicorn.

How do you run Gunicorn command vs upstart?

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.