Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a django app running on Nginx and uwsgi. The app works fine usually, but I have noticed one thing that is whenever I restart my server and try to work on my app I am getting Nginx 404 error and when I am looking at the error logs I see this error

[error] 2425#0: *1080 upstream prematurely closed connection while reading response header from upstream

After when I refresh the same Nginx 404 error page the app is working. This happens whenever I have rebooted the server and visited the app for the 1st time that I am getting these error messages on various links but when I have visited all the links and refreshed it a couple of times the same app works fine without any modification. I am also not getting any errors from the app because it is running on debug=True and so I think the error is not related to the app but unproperly configuring the server. This is my server config file. I am new to server setup so any help will be appreciated.

server {   

listen          80;
server_name     demo.myproject.com;
location /static {
    alias /var/www/myproject/project/env/var/static;
error_page   404              /404.html;
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;

   root        /var/www/myproject/project/;
   access_log  /var/www/myproject/nginx/project.com.access.log;
   error_log  /var/www/myproject/nginx/project.com.error.log;   

location /robots.txt {
     root /var/www/myproject/project; 

location / {
    include         uwsgi_params;
    uwsgi_pass unix:/tmp/uwsgi.sock;
    uwsgi_param UWSGI_PYHOME /var/www/myproject/project/env;
    uwsgi_param UWSGI_CHDIR /var/www/myproject/project;
    uwsgi_param UWSGI_MODULE project.wsgi:application;


I have consulted these responses http://stackoverflow.com/questions/12031935/upstream-prematurely-closed-connection-while-reading-response-header http://stackoverflow.com/questions/14044659/nginx-rails-and-oauth-upstream-prematurely-closed-connection

In the second response it says set the time out to 60s but as I have not set the time out specifically so the default is 60s as given in nginx module http://wiki.nginx.org/HttpUwsgiModule

share|improve this question
I've been getting this since I started to configure my Django settings. I've not touched any server configs and had the default Dj start page, but since I tried to put a db in for Dj I get a 502 & this upstream error :( –  marksweb Apr 12 '13 at 17:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.