Certbot免费https证书

当前工作目录为 /root

  1. 获取certbot

    wget https://dl.eff.org/certbot-auto
    chmod a+x certbot-auto
  2. 停止nginx

    service nginx stop
  3. 生成证书(如果后期生成报错,先删除原有certbot-auto,按第一步重新下载certbot即可)

    #使用-d追加多个域名,使用时请将邮箱换成自己的邮箱
    ./certbot-auto certonly --standalone --email [email protected] --agree-tos -d cdw.me -d www.cdw.me -d wiki.cdw.me
  4. 如果报错执行下面 certbot certonly --webroot -w 网站根目录 -d 网址 -m 邮箱 --agree-tos

  5. 查看生成的证书

    ls /etc/letsencrypt/live/
  6. 在nginx配置证书

    #证书位置
    ssl_certificate /etc/letsencrypt/live/cdw.me/fullchain.pem;
    # 私钥位置
    ssl_certificate_key /etc/letsencrypt/live/cdw.me/privkey.pem;
  7. 启动nginx

    service nginx start
  8. 编写更新脚本renew-cert.sh

    #!/bin/bash
    
    # 停止nginx
    /sbin/service nginx stop
    
    # 续签
    # --force-renew 强制更新
    /root/certbot-auto renew --force-renew
    
    # 启动nginx
    /sbin/service nginx start
    chmod a+x renew-cert.sh
  9. 自动更新https证书

    //crontab定时任务自动更新证书
    0 4 1 */2 * /root/renew-cert.sh >/root/crontab.log 2>&1

Let’s Encrypt 生成的免费证书为3个月时间,但是我们可以无限次续签证书

注意:定时任务可能会失败,请在/root/crontab.log中查看错误原因。
常见错误:
1.pip prints the following errors
解决方案:

# 备份pip配置
cp ~/.pip/pip.conf ~/.pip/pip.aliyun.conf
# 修改pip配置将镜像地址改为清华源
vi ~/.pip/pip.conf
  
  [global]
  index-url=https://pypi.tuna.tsinghua.edu.cn/simple

  [install]
  trusted-host=pypi.tuna.tsinghua.edu.cn

2.service:command not found
解决方案:

  # 使用完整的service完整路径,修改renew-cert.sh文件,在service命令前加上/sbin/
  /sbin/service nginx stop
  /sbin/service nginx start

版权声明:本文内容由互联网用户自发贡献,版权归作者所有,本社区不拥有所有权,也不承担相关法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件至:[email protected] 进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容。

<VirtualHost *:443>
    DocumentRoot "/home/www/shucai/flow_platform_material/shucai"
    ServerName c.wanwanws.com
    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/c.wanwanws.com/fullchain.pem   //之前生成的证书
    SSLCertificateKeyFile /etc/letsencrypt/live/c.wanwanws.com/privkey.pem    //之前生成的密钥
    <Directory "/home/www/shucai/flow_platform_material/shucai">
    Options FollowSymLinks ExecCGI
      AllowOverride All
      Order allow,deny
      Allow from all
     Require all granted
    </Directory>
 </VirtualHost>

猜你喜欢

转载自blog.csdn.net/weixin_41647577/article/details/84834392