网站设置了SSL通配型证书,也就是泛域名证书。为了实现mzihen.com和www.mzihen.com都301跳转到https://www.mzihen.com的效果,于是设置了2个conf文件。结果重启nginx的时候出现如下提示:
Stoping nginx… nginx: [warn] conflicting server name “www.mzihen.com” on 0.0.0.0:80, ignored
这只是个警告,并不影响网站访问,但是本着能完美就完美的原则,终于找到原因。
mzihen.com.conf配置文件
server
{
listen 80;
#listen [::]:80;
server_name mzihen.com www.mzihen.com;
index index.html index.htm index.php default.html default.htm default.php;
root /home/wwwroot/www.mzihen.com;
if ($host = 'mzihen.com') {
return 301 https://www.mzihen.com$request_uri;
}
……
}
www.mzihen.com.conf配置文件
server
{
listen 80;
server_name www.mzihen.com;
return 301 https://www.mzihen.com$request_uri;
}
在mzihen.com.conf和www.mzihen.com.conf里都设置了www.mzihen.com,所以在mzihen.com.conf配置文件了删掉www.mzihen.com就可以了。
现在想要将这2个配置文件合并为1个,一直没尝试成功。








server{ listen 80; #listen [::]:80; server_name www.mzihen.com mzihen.com; rewrite ^(.*) https://www.$server_name$1 permanent;}—————-
这样应该可以吧?
厉害了老杨,调整下顺序果然可以。。。赞!