我有 2 个网站(old-domain.com 和 new-domain.com),我准备关闭 old-domain.com 并重定向到 new-domain。因此,我将重写和返回行添加到我的 conf 文件中。catch all(return 301 *)在没有警告的情况下运行,但是当我转到特定页面(例如 old-domain.com/page-1)时,我收到证书警告:
此服务器无法证明它是 old-domain.com;其安全证书来自 new-domain.com。这可能是由于配置错误或攻击者拦截了您的连接所致。
两个域名都在同一个 IP 上,下面是我的 nginx 设置:
新域.conf:
server {
listen 80;
server_name new-domain.com;
}
server {
listen 433;
server_name new-domain.com;
ssl_certificate new-domain.cert;
ssl_certificate_key new-domain.cert_key;
ssl_client_certificate new-domain.client_cert_key;
}
旧域.conf:
server {
listen 80;
listen 433;
server_name old-domain.com;
ssl_certificate old-domain.cert;
ssl_certificate_key old-domain.cert_key;
ssl_client_certificate old-domain.client_cert_key;
#catch all - works, but causes invalid certificate
rewrite ^/page-1 https://new-domain.com/differnt-path/page-1-extra permanent;
#catch all - works without warning
return 301 https://new-domain.com;
答案1
Arewrite
是本地的,而 Aredirect
不是。您确实需要以rewrite
a结尾redirect
才能执行重定向。您还可以使用匹配的位置进行“重写”...
旧域.conf:
server {
listen 80;
listen 433;
server_name old-domain.com;
ssl_certificate old-domain.cert;
ssl_certificate_key old-domain.cert_key;
ssl_client_certificate old-domain.client_cert_key;
location ~ ^/page-1 {
return 301 https://new-domain.com/differnt-path/page-1-extra;
}
location ~ ^/page-2(/.*)?$ {
return 301 https://new-domain.com/differnt-path/page-2-extra$1;
}
rewrite ^/page-3 https://page-3/ redirect; # http 302!!!
#catch all - works without warning
return 301 https://new-domain.com;