免费HTTPS证书申请安装!Ubuntu + Let's Encrypt

57 篇文章 0 订阅
19 篇文章 0 订阅

 

步骤:

0. 开启http://demo.com/
1. ssh到linux远程服务器
2. 安装certbot,https://certbot.eff.org/docs/install.html

sudo apt-get update
sudo apt-get install certbot python-certbot-apache

3. 准备材料
域名 = demo.com, www.demo.com, blog.demo.com
路径 = /var/www/demo/
4. 申请证书

certbot certonly --webroot -w /var/www/demo/ -d demo.com -d www.demo.com -d blog.demo.com

提示成功:

Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/demo.com/fullchain.pem
...

5. 安装证书
6. 设置定时任务,自动更新证书:

sudo -i
crontab -e
0 0 1 * * certbot renew --post-hook "apache2ctl restart"

其中,post-hook的参数值是希望renew成功后 自动重启apache服务器,这里需要大家根据自己的情况修改下。
另外:letsencrypt证书有效期都是三个月,我们希望每个月1号凌晨都检查所有的证书,并自动更新证书。



 

常用命令:

certbot certificates
certbot --apache
certbot --nginx
certbot certonly 
certbot certonly --webroot -w /var/www/cms/ -d example.com -d www.example.com
certbot certonly --webroot -w /var/www/cms/ -d example.com -d www.example.com --deploy-hook /path/to/script/update-apache.sh
certbot renew
certbot renew --dry-run
certbot renew --pre-hook "service nginx stop" --post-hook "service nginx start"
certbot --apache -d example.com -d www.example.com -d other.example.net
certbot certonly --cert-name example.com

su root
crontab -e
* 4 * * 3 /root/scripts/certbot/auto-update-vhost-conf.sh

certbot --apache (这是apache专用命令,会自动搜索vhost虚机信息,由你选择后进行申请安装证书,并自动在apache里添加其域名的https配置文件,适用于域名较少的情况)

 

须知(个人理解):

0. 一个lets encrypt证书可以包含多个域名(例如demo.com和download.demo.com),但不能作为“泛域名”使用,例如*.demo.com
1. certbot是lets encrypt的一个申请证书的工具,证书是由lets encrypt这个证书中心(CA)颁发。
2. certbot不是常驻内存的服务(Service)或者后台脚本,只是一次行执行的工具,需要手动启动certbot逐个申请证书,或者搭配crontab -e来定时启动certbot以进行证书更新。
3. certbot有多种申请证书的方法,包括:
   自动模式(使用命令certbot --apache -d example.com -d www.example.com -d other.example.net 然后它会帮你申请证书并且安装到apache并且启用这个证书)
   手动模式(使用命令certbot certonly --webroot -w /var/www/cms/ -d example.com -d www.example.com 这个命令只是帮你申请证书,并不会帮你在服务器例如apache设置这个域名的https证书,需要自己弄后续的https)
4. 不能一次性为所有的域名(上百个)申请同一张https证书,有限制,需要手动指定某些域名

 

 

错误:

1. 配置错误

您的连接不是私密连接 NET::ERR_CERT_COMMON_NAME_INVALID
此服务器无法证明它是demo1.com;其安全证书来自demo2.com。出现此问题的原因可能是配置有误或您的连接被拦截了。

解决办法: 需要自己配置这个域名的https信息,包括域名项目文件的路径,https证书的位置(3个),端口,IP等等


2. 申请失败

IMPORTANT NOTES:
 - The following errors were reported by the server:


   Domain: www.ultimatemag.net
   Type:   connection
   Detail: Could not connect to
   http://www.xxx.net/.well-known/acme-challenge/Gs8QJJuSHYPTjbNVGDuIBHQmwCClGgsbRmxkWTvepCo


   Domain: ultimatemag.net
   Type:   connection
   Detail: Could not connect to
   http://xxx.net/.well-known/acme-challenge/n3jevLcCJnH32SgOgLxlt0G1hjTeWEy2uuDlOZ46zuE


   To fix these errors, please make sure that your domain name was
   entered correctly and the DNS A record(s) for that domain
   contain(s) the right IP address. Additionally, please check that
   your computer has a publicly routable IP address and that no
   firewalls are preventing the server from communicating with the
   client. If you're using the webroot plugin, you should also verify
   that you are serving files from the webroot path you provided.

解决办法: 保证http://xxx.net/可以访问,再登陆域名提供商(例如万网),检查其DNS设定,再试一遍。



 

相关推荐

内网·自签名https证书 https://blog.csdn.net/qq285744011/article/details/78126343
公网·收费·Godaddy HTTPS证书安装 https://blog.csdn.net/qq285744011/article/details/50855452
公网·免费·HTTPS证书,来自Let's Encrypt https://blog.csdn.net/qq285744011/article/details/78804223

强制全站HTTPS访问 https://blog.csdn.net/qq285744011/article/details/103302856
https://blog.csdn.net/qq285744011/article/details/103437693
Mac下信任自签名的HTTPS证书 https://blog.csdn.net/qq285744011/article/details/103425147
MacOSX apache 添加了HTTPs本地域名后不能访问,无错误提示,无法连接 https://blog.csdn.net/qq285744011/article/details/78188892
 


 

延伸阅读:

certbot/certbot
https://github.com/certbot/certbot/

User Guide for certbot
https://certbot.eff.org/docs/using.html

Linux定时任务Crontab命令详解
https://www.cnblogs.com/intval/p/5763929.html

使用 Certbot + Let's Encrypt 小步快跑的奔向 Https
https://laravel-china.org/topics/2525/using-certbot-lets-encrypt-small-step-run-towards-https

Let's Encrypt 给网站加 HTTPS 完全指南certbot
http://blog.csdn.net/cstopery/article/details/51911298

手把手教你在Nginx上使用CertBot
https://segmentfault.com/a/1190000005797776

利用Certbot工具快速给网站部署Let's Encrypt免费SSL证书
http://www.laozuo.org/9502.html

使用certbot为你的网站免费上https
http://www.jianshu.com/p/fb3733cd0d3b

shell script error [: 12: unexpected operator?
https://stackoverflow.com/questions/14934185/shell-script-error-12-unexpected-operator

Certbot and --apache modules looks for vhost conf files in sites-available causing missconfigurations in edge cases
https://github.com/certbot/certbot/issues/3791

linux shell脚本自动检测apache服务是否正常的诡异问题
http://blog.csdn.net/wangjunjun2008/article/details/50680381

[shell]对apache进程进行检测的脚本
http://blog.csdn.net/yagas/article/details/6748742

判断文件是否存在的shell脚本代码
http://www.jb51.net/article/34330.htm








 

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Rudon滨海渔村

花的越多,赚得越多...

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值