如何修复 nginx 重写重定向导致 certbot 验证错误

当在我的 nginx 配置中使用 rewrite 重定向到新域名时,我遇到 Let’s Encrypt 在使用 certbot --nginx 时无法验证域名所有权的问题。

我的重定向语句是

nginx_rewrite_example.conf
location / {
    rewrite ^/$ https://newdomain.com permanent;
    rewrite ^/(.*)$ https://newdomain.com/$1 permanent;
}

我通过改用此重定向语句修复了该问题:

nginx_return_301_redirect.conf
location / {
     return 301 https://newdomain.com$request_uri;
}

使用此语句后,我能够使用 certbot --nginx 而没有任何问题。


Check out similar posts by category: Nginx