使用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"
相关推荐
RPA机器人就用八爪鱼1 天前
八爪鱼RPA客服质检自动化:会话记录采集与关键词分析方案
运维·自动化·rpa
hoaxxcj1 天前
多智能体把云可靠性工程自动化:NeurIPS 2025 的 STRATUS 比 SOTA 强 1.5 倍,还顺手定了条“安全规范“
运维·安全·自动化·大模型·ai论文·前沿解读
后除1 天前
Debian 安装与使用 Certbot
后端·nginx·https
运维大师1 天前
【K8S 运维实战】39-etcd脑裂故障复盘
运维·kubernetes·etcd
tedcloud1231 天前
Kimi-K3 部署指南:大模型应用开发环境搭建实践
linux·运维·服务器·开源·音视频
大模型丫丫1 天前
GitHub Actions 自动化运维实战:从 CI/CD 到云端部署
运维·自动化·github
2501_915921431 天前
抓包鹰抓取系统 App 的流量,从底层读明文
网络协议·计算机网络·网络安全·adb·https·udp
山海鲸可视化1 天前
数字孪生技术:创新性破解城市高温难题
大数据·运维·数字孪生·数据可视化·可视化大屏
XR风云1 天前
docker buildx 忽略容器镜像服务的证书校验的方法
运维·docker·容器
去伪存真20251 天前
数字工厂与产线孪生的平台能力深度拆解
大数据·运维·人工智能·机器人