更新alpine Nginx容器中的Let’s Encrypt证书(certbot方式)

2.5k 记录 , , 一条评论

本文说明如何在Docker的alpine nginx容器中更新https证书,

非Docker容器请参考:使用Let’s Encrypt免费为网站加上HTTPS

步骤如下:

1、alpine中安装certbot

# apk add --no-cache certbot

2、在alpine容器中执行更新命令:

# 使用【默认配置目录】的更新命令
# certbot renew

# 使用【自定义配置目录】的更新命令
# certbot renew --config-dir /etc/nginx/conf.d/certs

# 使用【自定义配置目录】的更新命令,并且在更新完成后重启nginx
# certbot renew --config-dir /etc/nginx/conf.d/certs --post-hook "nginx -s reload" 

然后重启Nginx,搞定。

3、也可以使用定时任务自动执行,请参考文章《Docker使用cron定时任务》。

下一篇:

1 条评论

j
jonise says: 回复

alpine Nginx容器 报错 文件只读 该如何解决?
/etc/nginx/conf.d # certbot renew –config-dir /etc/nginx/conf.d/certs
Saving debug log to /var/log/letsencrypt/letsencrypt.log
The following error was encountered:
[Errno 30] Read-only file system: ‘/etc/nginx/conf.d/certs/.certbot.lock’
Either run as root, or set –config-dir, –work-dir, and –logs-dir to writeable paths.

回复 jonise 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

昵称 *