我的網站將更改 url,我正在嘗試應用重定向(HTTPS 到 HTTPS),但出現以下錯誤:
nginx: [warn] conflicting server name "old-name.example.com" on 0.0.0.0:443, ignored nginx.
這是我在 /etc/nginx/sites-enabled/myconf.conf 上的 nginx 組態檔:
server {
server_name old-name.example.com;
location / {
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
#
# Custom headers and headers various browsers *should* be OK with but aren't
#
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization,x-auth';
#
# Tell client that this pre-flight info is valid for 20 days
#
[some config....]
}
listen 443 ssl; # managed by Certbot
[ssl config...]
}
server {
if ($host = old-name.example.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name old-name.example.com;
return 404; # managed by Certbot
}
server {
listen 443 ssl;
server_name old-name.example.com;
return 301 $scheme://www.new-name.com$request_uri;
}
uj5u.com熱心網友回復:
在同一個埠上使用重復的服務器名稱監聽是沒有意義的,永遠不會選擇第二個服務器塊來處理請求。你可能需要類似的東西
server {
server_name www.new-name.com;
listen 443 ssl;
... ssl config for the www.new-name.com
location / {
... serve content
}
}
server {
server_name www.new-name.com;
listen 80;
return 301 https://www.new-name.com$request_uri;
}
server {
server_name old-name.example.com;
listen 80;
listen 443 ssl;
... ssl config for the old-name.example.com
return 301 https://www.new-name.com$request_uri;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/488104.html
