我按照Cerbot 的说明 在我的 Debian 服务器中为域获取 NGINX 的 HTTPS 证书,但 HTTPS 未正确重定向。
etc/nginx/conf.d/app.conf
我从 Certbot 的自动生成中得到以下内容:
server {
server_name mnpd.khkm.dev www.mnpd.khkm.dev;
# listen 8080;
server_tokens off;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
# return 301 https://mnpd.khkm.dev$request_uri;
proxy_pass http://mnpd.khkm.dev;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mnpd.khkm.dev/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mnpd.khkm.dev/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 = mnpd.khkm.dev) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name mnpd.khkm.dev www.mnpd.khkm.dev;
return 404; # managed by Certbot
}
在 Chrome 中,当我访问https://mnpd.khkm.dev/时,我得到:
mnpd.khkm.dev redirected you too many times.
Try deleting your cookies.
ERR_TOO_MANY_REDIRECTS
我找到了这个Stack Overflow 答案
,我查看了 Web 控制台中的“网络”选项卡,发现该页面不断被重定向到https://mnpd.khkm.dev/
. NGINX 配置应该侦听 HTTPS 端口 443,那么为什么它不加载并不断重定向呢?(我希望加载默认的 NGINX 页面。)