Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got an Ubuntu server configured with Nginx and uWSGI to serve Django which was setup and working with the default start page yesterday.

All I have done since is install MySQL and later PostgreSQL and add Db settings to Django and now I get a 502 Gateway Error and the upstream prematurely closed connection while reading response header from upstream error in my uwsgi error log.

I have had a look around and I've seen people suggest this can relate to a timeout setting and also that people have fixed it simply by reinstalling PHP, but I'd like to understand what exactly this means and hopefully how to fix it. Could someone possibly shed some light on this for me?

My uWSGI config looks like this;

# config
plugins = python
master = true
protocol = uwsgi
env = DJANGO_SETTINGS_MODULE=%(projectname).settings
pythonpath = %(base)/src/%(projectname)
module = %(projectname).wsgi
socket =
logto = %(base)/logs/uwsgi.log
daemonize = /var/log/uwsgi/mydomain.log

And my Nginx config looks like this;

server {
    listen 80;
    root /var/www/;
    #access_log /var/www/;
    error_log /var/www/;
    server_tokens off;

    location /startic/ { #STATIC_URL
            alias /var/www/; # STATIC_ROOT
            expires 30d;

    location /media/ { # MEDIA_URL
            alias /var/www/; # MEDIA_ROOT
            expires 30d;

    location / {
            include uwsgi_params;
share|improve this question
where is uwsgi_pass directive in your config? – cadmi Apr 13 '13 at 12:43
@cadmi sorry - my terminal didn't have enough lines to copy/paste it all out and I missed that off. It's in location / { - I've updated my question. – markwalker_ Apr 13 '13 at 13:00
try to add uwsgi_modifier1 30; after include uwsgi_patams; – cadmi Apr 13 '13 at 15:02
do you run syncdb after db settings has been added to – cadmi Apr 13 '13 at 15:05

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.