我有 3 个网站,domain1.com、domain2.com 和 domain3.com。
domain1.com 没有 SSL
domain2.com 只是重定向到 domain1
domain3.com 需要 ssl
这是我的设置:
域1.nginx
upstream domain1 {
server localhost:3009;
}
server {
listen 80;
server_name www.domain1.com
return 301 http://domain1.com$request_uri;
}
server {
root /domain1/priv/static;
listen 80;
server_name domain1.com;
location / {
proxy_pass http://domain1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
域2.nginx
server {
server_name www.domain2.com domain2.com;
return 301 http://domain1.com$request_uri;
}
域3.nginx
upstream domain3 {
server localhost:3019;
}
server {
listen 80;
server_name www.domain3.com domain3.com;
return 301 https://domain3.com$request_uri;
}
server {
root /domain3/priv/static;
listen 443 ssl;
server_name domain3.com;
ssl_certificate /etc/letsencrypt/live/domain3.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain3.com/privkey.pem;
location / {
proxy_pass http://domain3;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
实际情况:
domain1.com 运行正常
www.domain2.com 和 domain2.com 重定向到 domain1.com 完全没问题
www.domain1.com 重定向到 domain3.com,而它应该直接转到 domain1.com
domain3.com 应该重定向到 domain3.com 的 ssl 版本,但却重定向到 domain1.com
www.domain3.com 重定向到 domain3.com 的 ssl 版本
我究竟做错了什么?
以下是一些要点,有一些略微不同的设置,但存在同样的问题: https://gist.github.com/anonymous/6ba8865593c7c3e57f2035bafa3105b7