11 月 142024
 

之前是通过acme.sh 定期更新ssl文件,保证https的访问,但是无论docker还是nginx,都有个问题。如果acme.sh更新完,服务必须要重新启动才能读到,一旦ssl时间过期,影响使用,所以就尝试更新完证书,自动重启服务。但是查了很多acme.sh的hook都没用,没办法触发命令。测试了半天,才发现解决办法:

参考url:https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E

Nginx example:

acme.sh --install-cert -d example.com \
--key-file       /path/to/keyfile/in/nginx/key.pem  \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd     "service nginx force-reload"

(一个小提醒, 这里用的是 service nginx force-reload, 不是 service nginx reload, 据测试, reload 并不会重新加载证书, 所以用的 force-reload)

Nginx 的配置 ssl_certificate 使用 /etc/nginx/ssl/fullchain.cer ,而非 /etc/nginx/ssl/<domain>.cer ,否则 SSL Labs 的测试会报 Chain issues Incomplete 错误。

--install-cert命令可以携带很多参数, 来指定目标文件. 并且可以指定 reloadcmd, 当证书更新以后, reloadcmd会被自动调用,让服务器生效.

同样的docker重启,把reloadcmd   的命令 修改即可。后面测试强制更新,会把证书copy到对应位置,并执行相关重启命令。

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny