Nginx "upstream" directive is not allowed here

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;
    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:

1 answer

  • answered 2021-05-17 07:00 Daniil

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

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