使用certbot为网站启用https

1. 安装certbot客户端

复制代码
cd /usr/local/bin
wget https://dl.eff.org/certbot-auto
chmod a+x ./certbot-auto

2. 创建目录和配置nginx用于验证域名

复制代码
    mkdir -p /data/www/letsencrypt

    server {
        listen 80;
        server_name ~^(?<subdomain>.+).ninvfeng.com;

        location /.well-known/ {
            root /data/www/letsencrypt;
            allow all;
        }

        location / {
            return 301 https://$subdomain.ninvfeng.com$request_uri;
        }
    }

3. 生成证书

复制代码
certbot-auto certonly --webroot -w /data/www/letsencrypt -d jianli.ninvfeng.com

4. 配置nginx https

复制代码
server {
    listen       443;
    server_name  jianli.ninvfeng.com;

    root /data/www/jianli;

    location / {
        index index.php index.html;
    }

    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    if (!-e $request_filename) {
        rewrite ^/(.*) /index.php?$1 last;
    }
    

    ssl on;
    ssl_certificate /etc/letsencrypt/live/jianli.ninvfeng.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/jianli.ninvfeng.com/privkey.pem;

    ssl_session_timeout  5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers   on;
}

该方法生成的证书有效期为90天, 在到期前我们需要执行以下命令更新证书

复制代码
certbot-auto renew

0 0 1 * * certbot-auto renew  --quiet --renew-hook "nginx -s reload"
相关推荐
EverydayJoy^v^4 小时前
RH134学习进程——十二.运行容器(1)
linux·运维·容器
b***25115 小时前
电池组PACK自动化生产线的关键流程与核心优势
运维·自动化
哲伦贼稳妥6 小时前
职场发展-遇到以下情况请直接准备后手吧
运维·经验分享·其他·职场和发展
Exquisite.7 小时前
企业高性能web服务器(4)
运维·服务器·前端·网络·mysql
北塔软件7 小时前
北塔方案 | 政府行业IT运维解决方案
运维·it运维·解决方案·政务
cg_ssh8 小时前
Docker 下启动 Nacos 3.1.1 单机模式
运维·docker·容器
修己xj8 小时前
使用 Docker 部署 SQL Server 并导入 .mdb 文件的完整指南
运维·docker·容器
郝亚军9 小时前
ubuntu-18.04.6-desktop-amd64安装步骤
linux·运维·ubuntu
Web极客码9 小时前
CentOS 7.x如何快速升级到CentOS 7.9
linux·运维·centos
一位赵10 小时前
小练2 选择题
linux·运维·windows