一台服务器上的多个域指向错误的站点

时间:2014-01-29 09:48:25

标签: nginx multiple-domains server-configuration

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

显示错误消息 -

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 个答案:

答案 0 :(得分:9)

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

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

答案 1 :(得分: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/;
    }
}

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

答案 2 :(得分:2)

如果有/etc/nginx/sites-enabled/等临时文件,请查看~default目录。删除它并解决问题。

来源:@OmarIthawi nginx error "conflicting server name" ignored

答案 3 :(得分:1)

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

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

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

我的2美分......

相关问题