【问题标题】:Nginx "upstream" directive is not allowed here这里不允许使用 Nginx “上游”指令
【发布时间】:2021-08-06 10:01:42
【问题描述】:

我正在尝试使用 uwsgi 和 nginx 建立一个 Django 网站。我创建了配置文件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;
    }
}

它给出了这个错误:

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

我不知道为什么会这样。我遵循了这个教程:https://tonyteaches.tech/django-nginx-uwsgi-tutorial/

【问题讨论】:

    标签: django nginx uwsgi


    【解决方案1】:

    问题是我在 http 标签之前包含了配置文件。 应该是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-05
      • 1970-01-01
      • 2021-09-10
      • 2014-10-08
      • 1970-01-01
      相关资源
      最近更新 更多