# HTTP 入口:ACME 验证 + HTTPS 跳转 # # 【关键】这个文件必须常驻,且不能引用任何证书文件。 # 首次部署时证书尚不存在,如果 nginx 加载了带 ssl_certificate 的 server 块, # 会直接 [emerg] cannot load certificate 退出;而申请证书又必须要有 80 端口可用 # —— 形成死锁。因此所有 HTTPS server 块统一放到 /etc/nginx/ssl.d/, # 由 nginx/enable-ssl.sh 在证书就绪后再启用。 server { listen 80 default_server; server_name _; # 健康检查探针(容器 HEALTHCHECK 使用),不跟随 301 location = /healthz { access_log off; default_type text/plain; return 200 "ok\n"; } # ACME HTTP-01 验证 # acme.sh 通过 webroot 写入 /var/www/certbot/.well-known/acme-challenge/ # 这是宿主机目录,nginx 容器以只读方式 bind mount location /.well-known/acme-challenge/ { root /var/www/certbot; default_type text/plain; } location / { return 301 https://$host$request_uri; } }