干货 | 利用certbot获得免费的https证书

certbot官网教程

https://certbot.eff.org/lets-encrypt/centosrhel7-nginx

环境,其他环境可以参考certbot官网,大同小异

centos7
nginx

一、安装

yum install certbot python2-certbot-nginx

二、扩展插件:DNS plugin

yum install python2-certbot-dns-rfc2136

三、开始配置

certbot --nginx

会要求你输入联系邮箱,并选择相关配置:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): 【输入你的邮箱】
Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org

- - - - - - - - - - - - 【是否同意协议】 - - - - - - - - - - - - - - - - - - - - -
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

- - - - - - - - - - - - 【是否订阅certbot的相关资讯】- - - - - - - - - - - - - - - - - - - -
Would you be willing 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: N

Which names would you like to activate HTTPS for?
- - - - - - 【certbot会去扫描的/etc/nginx/conf目录下的所有配置文件,如果没有扫描出来,就要看自己的文件名是否跟域名对应】- - - - - 
1: 你的域名
2: 你的域名
3: 你的域名
4: 你的域名
5: 你的域名
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):  
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for 你的域名
http-01 challenge for 你的域名
http-01 challenge for 你的域名
http-01 challenge for 你的域名
http-01 challenge for 你的域名
Waiting for verification...
Cleaning up challenges
Resetting dropped connection: acme-v02.api.letsencrypt.org
Deploying Certificate to VirtualHost /etc/nginx/conf.d/你的域名.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/你的域名.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/你的域名.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/你的域名.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/你的域名.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
# 不重定向
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
# certbot 会自动修改你的nginx配置,添加重定向配置
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - -【选择是否进行重定向,建议重定向,可以保证别人没有输入https时生效】- - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/你的域名.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/你的域名.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/你的域名.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/你的域名.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/你的域名.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://你的域名,
https://你的域名,https://你的域名,https://你的域名,https://你的域名,
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=你的域名
https://www.ssllabs.com/ssltest/analyze.html?d=你的域名
https://www.ssllabs.com/ssltest/analyze.html?d=你的域名
https://www.ssllabs.com/ssltest/analyze.html?d=你的域名
https://www.ssllabs.com/ssltest/analyze.html?d=你的域名
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  • 出现以下文字标识成功
IMPORTANT NOTES:【注意你的证书存放目录】
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/你的域名/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/你的域名/privkey.pem
   Your cert will expire on 2019-06-23. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

四、注意事项

  • htpps证书续订命令,90天会过期:

certbot renew

  • 测试续订功能

certbot renew --dry-run

  • htpps证书自动续订(利用linux的cron job功能)

crontab –e

  • 添加以下代码:
0 0,12 * * * python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew 






【欢迎转载,请保留出处:https://www.jianshu.com/p/5fb387e3d929】

你可能感兴趣的:(干货 | 利用certbot获得免费的https证书)