0%

基于Certbot docker部署letsencrypt证书

仓库地址

1
https://registry.hub.docker.com/r/certbot/certbot

官方参考

1
https://certbot.eff.org/docs/install.html#running-with-docker

pull 镜像

1
docker pull certbot/certbot

基于内置webserver部署

这个方案的坏处是需要启动内置的nginx服务器占用80和443端口.

创建两个目录

1
2
/etc/letsencrypt
/var/lib/letsencrypt

运行镜像

1
2
3
4
5
docker run -it --rm --name certbot \
-v "/etc/letsencrypt:/etc/letsencrypt" \
-v "/var/lib/letsencrypt:/var/lib/letsencrypt" \
-p 80:80 -p 443:443 \
certbot/certbot certonly

提问用webserver部署或者用webroot

1
2
3
4
5
6
7
How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 1

我们用临时服务器方便点所以选择1, 如果用2的话需要自己设置验证文件.

提示你输入邮箱

1
2
3
Plugins selected: Authenticator standalone, Installer None
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel):

不用看了,就是我已阅读并同意….

1
2
3
4
5
6
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: a

想不想接受他给你发邮件

1
2
3
4
5
6
7
8
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y

输入你的域名, 例如: yourself.hostname.xxx, 这里不要输错了, 输错无法后退, 只能重来.

1
2
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel): yourself.hostname.xxx

看到

1
2
3
4
5
6
7
8
9
10
11
12
13
14
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/yourself.hostname.xxx/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/yourself.hostname.xxx/privkey.pem
Your cert will expire on 2020-12-13. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:

Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

完成

证书保存在

1
/etc/letsencrypt/live/yourself.hostname.xxx/