使用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"
相关推荐
Plastic garden1 分钟前
Docker(1)
运维·docker·容器
s_w.h14 分钟前
【 linux 】动静态库的制作
linux·运维·服务器·算法·bash
songjxin17 分钟前
Nginx 日志分析可视化面板
运维·nginx
专注VB编程开发20年1 小时前
安卓APP与服务器通讯技术,文件传输和文字消息收发
运维·服务器
Agent手记1 小时前
电信运营商如何用AI实现携号转网自动处理?基于实在Agent的业务自动化落地与TARS大模型解析方案
运维·人工智能·ai·自动化
wanhengidc1 小时前
云手机搬砖 像僵尸开炮
运维·网络·智能手机·云计算
_Voosk2 小时前
FreeBSD 使用代理运行命令
linux·运维·freebsd
信息安全失业大专人员2 小时前
HTTP/HTTPS 协议精髓与 WAF(Web 应用防火墙)架构防线大底座
web安全·http·信息安全·https·企业信息安全
lihui_cbdd2 小时前
HPC 集群上 OpenMM GPU 多版本安装实战指南
运维·服务器·人工智能·计算化学
志栋智能2 小时前
超越监控:超自动化巡检提供的主动价值
运维·网络·人工智能·自动化