使用 Nginx 的 location 解决负载代理和 Let's Encrypt 证书续签问题
目前某个项目项目使用了 https ,如果这个证书是 let's encrypt 颁发的。那么就需要每三个月续签一次。用acme.sh
续签的时候,需要访问 http 上的 .well-known
目录验证。
但这个项目做了负载,会将请求反向代理到子服务器 x/y/z 上去。
类似这样
server {
listen 80;
listen 443;
ssl on;
ssl_certificate /path/to/domain.fullchain.cer;
ssl_certificate_key /path/to/domain.key;
server_name domain.com
location / {
proxy_pass http://newstproxy;
proxy_set_header Host $host;
proxy_set_header Connection close;
proxy_connect_timeout 60s;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
这时候 .well-known 目录下的请求同样会转发到 x/y/z 上去。用 Let's encrypt 续签的时候就失败了,如何解决?
这时候我们加一个location ,让 Nginx 遇到这个目录的时候,不走反向代理规则就可以了。
location ^~ /.well-known {
root /PATH/TO/WEB_ROOT;
}
这样 /.well-known 请求就会转到这台服务器的 /PATH/TO/WEB_ROOT/.well-known 去,这样续签就正确了。
阅读 862
1 声望
0 粉丝
0 条评论
得票最新