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

Sta*_*erg 6 server-configuration nginx multiple-domains

使用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.
Run Code Online (Sandbox Code Playgroud)

我已经在/ 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;

        }

}
Run Code Online (Sandbox Code Playgroud)

我已经检查过,并且/ sites-enabled中没有默认文件.猜测Nginx主配置中可能存在错误设置但不确定要查找的内容.

JCl*_*rke 9

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

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


pbo*_*pbo 2

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

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