skip to Main Content

I’m trying to set up a Django website with uwsgi and nginx. I created configuration file mysite.conf:

# the upstream component nginx needs to connect to
upstream django {
    server unix:///home/path/to/mysite/mysite.sock;
}

# configuration of the server
server {
    listen      80;
    server_name mydomain.com www.mydomain.com;
    charset     utf-8;
    # max upload size
    client_max_body_size 350M;

    # Django media and static files
    location /media  {
        alias /home/path/to/mysite/media;
    }
    location /static {
        alias /home/path/to/mysite/static;
    }

    # Send all non-media requests to the Django server.
    location / {
        uwsgi_pass  django;
        include     /home/path/to/mysite/uwsgi_params;
    }
}

And it gives this error:

nginx: [emerg] "upstream" directive is not allowed here in /etc/nginx/sites-enabled/mysite.conf:2

I don’t why it happens. I followed this tutorial: https://tonyteaches.tech/django-nginx-uwsgi-tutorial/

2

Answers


  1. Chosen as BEST ANSWER

    The problem was that i included configuration files before http tag. It should be:

    http {
        include /etc/nginx/sites-enabled/*;
        ...
    }
    

  2. This can also happen if your file is being deployed over the directory /etc/nginx/conf.d/ but the default config is including files from http.d instead:

    include /etc/nginx/http.d/*.conf;
    

    so try also to deploy it over /etc/nginx/http.d/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search