Certbot配置Let‘s Encrypt的https_ssl证书以及过程中出现的问题

还是在迁移服务器项目遇到的问题,之前都是用的Let's Encrypt申请的免费证书,但是用命令在服务器上执行时,居然报错了

[root@j certbot]# ./letsencrypt-auto
Skipping bootstrap because certbot-auto is deprecated on this system.
Upgrading certbot-auto 1.12.0 to 1.13.0...
Replacing certbot-auto...
Your system is not supported by certbot-auto anymore.
Certbot cannot be installed.
Please visit https://certbot.eff.org/ to check for other alternatives.

没办法了,只能查资料了

去certbot官方github上https://github.com/certbot/certbot/releases查了一下原因

起因是官方从1.9.0版本在所有基于Debian或RHEL的系统上,certbot-auto开始弃用,原因是certbot-auto是基于python2编写的,python 2去年已经GG,certbot团队又懒得移植到python3(我瞎说的)。

去certbot官方github上https://github.com/certbot/certbot/releases查了一下原因

起因是官方从1.9.0版本在所有基于Debian或RHEL的系统上,certbot-auto开始弃用,原因是certbot-auto是基于python2编写的,python 2去年已经GG,certbot团队又懒得移植到python3(我胡说的),具体看下面官方解释

在Certbot 1.11.0这个版本我们看到官方给出了解释https://community.letsencrypt.org/t/certbot-auto-no-longer-works-on-debian-based-systems/139702/7

那么我们现在如何来安装Certbot

在上面官方也给出啊了解决方案,使用snap来进行安装

那么什么是snap,简单介绍一下snap

什么是snap,snap安装包是Canonical公司发布的全新的软件包管理方式,它类似一个容器拥有一个应用程序所有的文件和库,各个应用程序之间完全独立。所以使用snap包的好处就是它解决了应用程序之间的依赖问题,使应用程序之间更容易管理。但是由此带来的问题就是它占用更多的磁盘空间。

2|0二、安装 let'sencrypt

我这里是放在centos下来进行的

先进行安装依赖等配置

[root@j certbot]# yum install epel-release                 # 安装epel
[root@j certbot]# yum install snapd                        # 安装snapd
[root@j certbot]# systemctl enable --now snapd.socket      # 启用snapd.socket
[root@j certbot]# ln -s /var/lib/snapd/snap /snap          # 创建软链接
[root@j certbot]# snap install --classic certbot           # 安装certbot
[root@j certbot]# ln -s /snap/bin/certbot /usr/bin/certbot # 创建certbot软链接

如果之前安装过Certbot出现了问题,可以进行重装

[root@j certbot]# yum remove certbot                      # 卸载certbot
[root@j certbot]# rm /usr/local/bin/certbot-auto          # 删除安装文件
[root@j certbot]# rm -rf /opt/eff.org/certbot

3|0三、证书生成

我这里环境是nginx

使用https一定要先在nginx开启http_ssl_module模块,不然会出现nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf 有的话可以跳过

如果没有的话需要重新编译安装一下

 

[root@j sbin]# cd /usr/local/nginx/sbin/           # nginx现有目录
[root@j sbin]# ./nginx -V                          # nginx现有模块
nginx version: nginx/1.19.5
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_flv_module 

可以看到configure arguments:后面的安装模块

所以我们在新的安装目录需要带上原有的

[root@j nginx-1.19.5]# cd /usr/local/src/nginx-1.19.5    # 进入新目录   
[root@j nginx-1.19.5]# ./configure --prefix=/usr/local/nginx --with-http_flv_module  --with-http_ssl_module   #安装ssl模块
[root@j nginx-1.19.5]# make # make安装,这里不要像以前一样 make&make install 否则会覆盖原有目录
[root@j nginx-1.19.5]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak  #nginx做原有备份
[root@j nginx-1.19.5]# cp ./objs/nginx /usr/local/nginx/sbin/  # nginx如运行 先停止
[root@j nginx-1.19.5]# /usr/local/nginx/sbin/nginx -V    #查看模块是否安装成功
[root@j nginx-1.19.5]# cd /usr/local/nginx/sbin/ # 运行nginx
[root@j sbin]# cd /usr/local/nginx/sbin/ 
[root@j sbin]# ./nginx 

执行之前我们先把nginx先停止,否则会占用80端口

接下来我们执行下方命令来进行执行,我这里*是做通配符

certbot certonly --nginx --email youremail@email.com -d x.域名.com -d *.域名.com

如果提示:

 

Saving debug log to /var/log/letsencrypt/letsencrypt.log Could not choose appropriate plugin: The nginx plugin is not working; there may be problems with your existing configuration. The error was: NoInstallationError("Could not find a usable 'nginx' binary. Ensure nginx exists, the binary is executable, and your PATH is set correctly.")

是因为没有将nginx放到环境变量中,设置nginx软连接

 
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
ln -s /usr/local/nginx/conf/ /etc/nginx

生成之后我们会在/etc/letsencrypt/live/x.域名.com目录下找到我们生成的证书

那么我们该怎么进行nginx配置

我这里简单写一个conf,需要http和https并存以及ssl调优可另外搜索查看

 
server
{
    listen 80;
    listen 443 ssl;
    server_name x.域名.com;
    charset utf8;
    
     #ssl on;
        ssl_certificate /etc/letsencrypt/live/x.域名.com/fullchain.pem; 
        ssl_certificate_key /etc/letsencrypt/live/x.域名.com/privkey.pem;
        ssl_protocols TLSv1.3 TLSv1.2;

        ssl_prefer_server_ciphers on;    # Forward Secrecy
        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout 30m;
    #REWRITE-END
    location / {
      proxy_pass http://127.0.0.1:9999;
    }
    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    

    access_log  /usr/local/nginx/logs/x.域名.com.log;
    error_log  /usr/local/nginx/logs/x.域名.com.log;
}

重载nginx,更新证书certbot renew

然后我们访问域名,查看下域名

4|0四、certbot自动定时续期证书

certbot renew #手动测试,查看证书过期时间

certbot renew --force-renewal #忽略证书过期时间,直接重置证书时间

crontab -e #定时任务

0 0 1 * * /usr/bin/certbot renew --force-renewal #编辑文件

我这里由于nginx没有关闭所以80端口还在占用所以就不演示了,更新证书一定要先停止nginx

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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证书,提升网站的安全性和可信度。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值