最新版 Let’s Encrypt免费证书申请步骤,保姆级教程

最近将域名迁到了google domain,就研究了一下Let’s Encrypt的域名证书配置。发现网上找到的教程在官方说明中已经废弃,所以自己写一个流程记录一下。

步骤方法官方文档见:https://eff-certbot.readthedocs.io/en/stable/install.html#installation

snapd官方文档见:https://certbot.eff.org/instructions

1. 安装snapd
  • centos(这里我使用的是这个系统)
    sudo yum install snapd
    sudo systemctl enable --now snapd.socket
    sudo ln -s /var/lib/snapd/snap /snap
    

  • ubuntu的
    $ sudo apt update
    $ sudo apt install snapd
    

测试一下:

$ sudo snap install hello-world
hello-world 6.4 from Canonical✓ installed
$ hello-world
Hello World!
2. 使用snapd安装certbot
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
3. 生成证书(需要指定nginx)

👉 手动安装nginx

certbot certonly --nginx --nginx-ctl /usr/local/nginx/sbin/nginx --nginx-server-root /usr/local/nginx/conf

这里的certonly就是只下载对应文件,不进行配置nginx,适用于自己配置或者更新使用。去掉则会帮你进行配置nginx(我没有试用)。

可能出现的问题:

The error was: PluginError(‘Nginx build is missing SSL module (–with-http_ssl_module).’)

提示这个错误是因为目前nginx缺少–with-http_ssl_module这个模块,我们要添加这个模块。重新编译nginx

进入nginx下载的目录

./configure --prefix=/usr/local/nginx --with-http_ssl_module

编译完成后

make

make install

/usr/local/nginx/sbin/nginx -s stop

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

使用 /usr/local/nginx/sbin/nginx -V 查看是否生效

[root]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.23.2
built by gcc 10.2.1 20200825 (Alibaba 10.2.1-3 2.32) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module

生效,重新执行上面的命令即可。

4. 生成证书

执行上面的命令后,程序会让你确认你的邮箱和你的域名,确认完成后会将证书文件生成在指定目录中。

certbot certonly --nginx --nginx-ctl /usr/local/nginx/sbin/nginx --nginx-server-root /usr/local/nginx/conf
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [这里输入你的邮箱]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.3-September-21-2022.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 [选Y 继续]
Account registered.

Which names would you like to activate HTTPS for?
We recommend selecting either all domains, or all domains in a VirtualHost/server block.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: whrss.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel):  [这里不需要输入,回车选所有]
Requesting a certificate for whrss.com

Successfully received certificate.
Certificate is saved at: 
# [这里告诉我们生成的文件路径和有效期]
/etc/letsencrypt/live/whrss.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/whrss.com/privkey.pem
This certificate expires on 2023-03-02.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

5. Nginx.conf的配置
server{
        #监听443端口
        listen 443 ssl;
        #对应的域名,空格分隔域名就可以了
        server_name whrss.com; 
        #第一个域名的文件
        ssl_certificate /etc/letsencrypt/live/whrss.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/whrss.com/privkey.pem;
        # 其他配置
        ssl_session_timeout 5m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
        ssl_prefer_server_ciphers on;
        #这是我的主页访问地址,因为使用的是静态的html网页,所以直接使用location就可以完成了。
        location / {
            root   /;
            index  /;
            proxy_pass http://127.0.0.1:9091;
            proxy_set_header Host $host:443;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Via "nginx";
        }
}

以上!!

let's encrypt是一个非盈利性质的机构,致力于提供免费的SSL证书服务,以促进整个互联网的安全性。在官网上,他们提供了一键式免费申请SSL证书的脚本,使得用户可以快速而简便地获取自己网站的SSL证书。 这个一键式免费申请SSL证书脚本的使用非常简单。首先,用户需要在自己的网站服务器上安装并配置好Certbot工具。Certbot是一个由let's encrypt官方开发的自动化工具,用于申请和更新SSL证书。 在安装和配置好Certbot之后,用户只需要在命令行中输入一条简单的指令,就可以申请自己网站的SSL证书了。具体指令如下: $ sudo certbot certonly --standalone -d <your_domain> 其中,“<your_domain>”替换为用户自己的域名。这条指令的作用是告诉Certbot以standalone模式运行,并申请一个新的证书,该证书将与用户输入的域名关联。 Certbot会自动与let's encrypt服务器进行通信,验证用户所拥有的域名和服务器的控制权。一旦验证通过,Certbot就会生成一个有效期为90天的SSL证书,并将其保存在用户指定的位置。 用户可以根据自己的需要选择将证书文件保存到哪个目录,以及将其用于哪个Web服务器(例如Apache或Nginx)。 值得一提的是,这个一键式免费申请SSL证书脚本还支持自动续订证书的功能。Certbot会在证书即将过期之前自动执行更新过程,以确保用户的网站能够持续使用最新的SSL证书。 总之,let's encrypt官网提供的一键式免费申请SSL证书脚本极大地简化了证书申请和管理的过程,让网站拥有更安全可靠的加密通信。用户只需几个简单的步骤,就能轻松获得免费的SSL证书,提升网站的安全性和可信度。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

了迹奇有没

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值