我不明白为什么会nginx
引发错误conflicting server name
。
我的项目在两个域上运行 -foo.com
和bar.com
。设置完成后nginx
,我安装了let's encrypt
证书,该证书在 中添加了一个服务器块sites-available/myproject
。
然后我尝试设置从www.foo.com
和www.bar.com
到的重定向foo.com
,bar.com
但这两个域不起作用。
sudo nginx -t
nginx: [warn] conflicting server name "www.foo.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.bar.com" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
同样的节目error.log
这是sites-available/myproject
server {
listen 80;
server_name www.bar.com;
return 301 $scheme://bar.com$request_uri;
}
server {
listen 80;
server_name www.foo.com;
return 301 $scheme://foo.com$request_uri;
}
server {
server_name foo.com bar.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/futilestudio/myproject;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/foo.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/foo.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = bar.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = foo.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name 178.128.xxx.xxx foo.com bar.com;
return 404; # managed by Certbot
}
所以我想要的是将所有文件重定向www
到non-www
安全的目录。你知道问题出在哪里吗?