6

使用 Nginx,我为一台服务器创建了一个多域设置,该服务器由四个单独的站点组成。当我启动 Nginx 时,我收到一条错误消息,并且这些站点似乎混淆了,因为输入一个 url 会导致另一个站点之一。

显示的错误消息 -

Restarting nginx: nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
nginx.

我已经在 /sites-available 下的各自文件中以类似的方式设置了所有四个域 -

server {
        listen   80;

        root /var/www/example.com/public_html;
        index index.php index.html index.htm;

        server_name example.com www.example.com;

        location / {
                try_files $uri $uri/ /index.html;
        }

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;

        }

}

我检查过,/sites-enabled 中没有默认文件。猜测 Nginx 主配置中可能存在错误设置,但不确定要查找什么。

4

4 回答 4

9

nginx.conf从包含指令中的路径加载其外部服务器文件。

如果您有一个文件include /etc/nginx/conf.d/*.conf;并且它的符号链接到include /etc/nginx/sites-enabled它将加载该文件两次,这将导致该错误。

于 2014-04-14T17:15:49.657 回答
3

我在本地机器上的 Ubuntu/nginx/gunicorn/django 1.9 站点遇到了同样的问题。我的 /etc/nginx/sites-enabled 中有两个 nginx 文件。删除任何一个允许剩余站点工作。将这两个文件放入最终总是会转到两个站点之一。我不确定它是如何选择的。

因此,在查看了几个堆栈溢出问题但没有找到解决方案后,我去了这里: http: //nginx.org/en/docs/http/request_processing.html

最终,您可以在一个启用站点的文件中拥有多个服务器,因此我更改为:

server {
    listen 80;
    server_name joelgoldstick.com.local;
    error_log    /var/log/nginx/joelgoldstick.com.error.log debug;
    location / {
        proxy_pass http://127.0.0.1:8002;
    }
    location /static/ {
        autoindex on;
        alias /home/jcg/code/python/venvs/jg18/blog/collect_static/;
    }
}

server {
    listen 80;
    server_name cc-baseballstats.info.local;
    error_log    /var/log/nginx/baseballstats.info.error.log debug;
    location / {
        proxy_pass http://127.0.0.1:8001;
    }
    location /static/ {
        autoindex on;
        alias /home/jcg/code/python/venvs/baseball/baseball_stats/collect_static/;
    }
}

我现在可以在本地访问我的两个网站

于 2016-02-20T19:15:14.197 回答
2

检查/etc/nginx/sites-enabled/目录是否有任何临时文件,例如~default. 删除它并解决问题。

信用:@OmarIthawi nginx 错误“冲突的服务器名称”被忽略

于 2014-04-06T23:00:50.233 回答
1

在我的情况下,没有启用网站也没有双重包括....

解决方案是避免对“listen 80”和“server_name”引用进行多个引用(如果您将所有 conf.d 文件视为一个整体)...

在我的情况下,default.conf 和 kibana.conf 都包含对这些人的引用......我在默认情况下评论了一个并且问题解决了!

我的 2 美分....

于 2015-05-05T00:01:13.373 回答