let's encrypt 申请 https 证书

ssl证书使用 Let’s Encrypt 免费证书,证书有效期是90天,需要执行定时更新证书脚本

参考:
https://www.jianshu.com/p/6ea81a7b768f
https://learnku.com/laravel/t/2525/using-certbot-lets-encrypt-small-step-run-towards-https

安装

使用官方的申请工具 Certbot, 官网有安装步骤,选择系统有相应的步骤
这里使用的ubuntu,nginx

$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo add-apt-repository universe
$ sudo add-apt-repository ppa:certbot/certbot
$ sudo apt-get update
$ sudo apt-get install certbot python-certbot-nginx

更快捷的申请证书方式(推荐)

certbot --nginx

在运行此命令时有以下的错误,以为这个add-apt-repository universe运行的有问题

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 299: ordinal not in range(128)

又运行了一遍,已经全局设置过了

'universe' distribution component is already enabled for all sources

参考以下文章,运行此命令
https://github.com/certbot/certbot/issues/...

grep -r -P '[^\x00-\x7f]' /etc/letsencrypt /etc/nginx

运行后出现下图
let's encrypt 申请 https 证书
把汉字删除后后再运行 certbot --nginx后正常

以下申请方式可以参考

申请证书

首先设置/.well-known/acme-challenge/ 节点

server {
    listen  80;
    server_name a.com;
    error_page 500 502 503 504  /50x.html;
    # 配置此节点确认站点所有权
    location /.well-known/acme-challenge/ {
        alias /var/www/challenges/;
        try_files $uri =404;
    }

    location / {
        proxy_pass         http://localhost:9005;
        proxy_redirect     off;
        proxy_set_header   Host              $host;
        proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }
}

申请证书的三种方式

#推荐 手动创建认证文件
certbot certonly --manual -w /var/www/challenges/ -d a.com   # 目录是创建文件可以被外网访问的一个文件夹,可以是项目文件夹,也可以是自定义的,自定义的需要在nginx上单独声明
#这种方式也可以,和上面的基本一致,上面的是手动生成文件,这条是自动生成文件,可能不成功
certbot certonly --webroot -w /var/www/challenges/ -d a.com
#这种方式不推荐,需要关闭nginx服务才能执行
certbot certonly --standalone --email your@email.com -d a.com

执行第一种命令方式,比较重要的一点是上面 /var/www/challenges 这个目录下需要手动生成一个文件,内容在执行命令后会得到,目的是让外网能检测到这个站点是自己的站点,参考下面介绍

有几个选项,选择选择一下 A 或者 Y
然后重点是下面,复制这个字符串,然后到/var/www/challenges创建一个文件ZIVnpTqot49eJ35qVjPS8_fONP0TV1AMtQDODffrb6g,内容为ZIVnpTqot49eJ35qVjPS8_fONP0TV1AMtQDODffrb6g.zrG5oFD2J6jl1kToZ-gFtyrO6rPU-VGyNq-kHZ8PKPg,然后访问一下http://a.com/.well-known/acme-challenge/ZIVnpTqot49eJ35qVjPS8_fONP0TV1AMtQDODffrb6g,可以访问再按回车下一步
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Create a file containing just this data:

ZIVnpTqot49eJ35qVjPS8_fONP0TV1AMtQDODffrb6g.zrG5oFD2J6jl1kToZ-gFtyrO6rPU-VGyNq-kHZ8PKPg

And make it available on your web server at this URL:

http://a.com/.well-known/acme-challenge/ZIVnpTqot49eJ35qVjPS8_fONP0TV1AMtQDODffrb6g

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue

成功后的提示

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/a.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/a.com/privkey.pem
   Your cert will expire on 2019-05-23. 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
本作品采用《CC 协议》,转载必须注明作者和本文链接
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!