ngnix - 在/ etc / nginx / sites-enabled / django

时间:2017-02-02 13:01:46

标签: django nginx

意外删除的conf nginx填充/etc/nginx/sites-enabled/django ,然后使用相同的配置设置填充它。得到以下错误:

  Feb 02 12:56:53 solomon nginx[32004]: nginx: [emerg] duplicate upstream "app_server" in /etc/nginx/sites-enabled/django.save:1
Feb 02 12:56:53 solomon nginx[32004]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 02 12:56:53 solomon systemd[1]: nginx.service: Control process exited, code=exited status=1
Feb 02 12:56:53 solomon sudo[31990]: pam_unix(sudo:session): session closed for user root
Feb 02 12:56:53 solomon systemd[1]: Failed to start A high performance web server and a reverse proxy server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit nginx.service has failed.
-- 
-- The result is failed.
Feb 02 12:56:53 solomon systemd[1]: nginx.service: Unit entered failed state.
Feb 02 12:56:53 solomon systemd[1]: nginx.service: Failed with result 'exit-code'.

配置,以前肯定有效。我做错了什么吗?:

 upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /usr/share/nginx/html;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name _;

    keepalive_timeout 5;

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/django_project/media;
    }

    # your Django project's static files - amend as required
    location /static {
        alias /home/django/django_project/django_project/static; 
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;
    }
}

3 个答案:

答案 0 :(得分:2)

如果目录(/etc/nginx/sites-enabled/django)中有其他配置文件,其上游名称与“app_server”相同,则会出现上游错误。

所以将'app_server'替换为任何其他名称。运行nginx -t检查是否有错误,然后重新启动nginx,

答案 1 :(得分:1)

如果您在终端 cat /etc/nginx/nginx.conf 你会看到这两行:

include /etc/nginx/conf.d/*.conf;
<块引用>

这意味着 Nginx 加载所有文件 .conf (for example if you are using dokku to deploy your app, you will see dokku.conf which contain "include /home/dokku/*/nginx.conf;" itself) 这意味着加载所有 /home/dokku/whatever-folder/nginx.conf

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

答案 2 :(得分:0)

在我的情况下出现此问题,因为我的配置文件在/etc/nginx/conf.d中,并且我在/etc/nginx/sites-enabled/中也有指向它的符号链接。不确定nginx如何加载文件,但显然它已加载两次。无论我为上游选择什么名称,我都会遇到重复错误。删除符号链接可解决此问题。