使用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"
相关推荐
IT大白鼠2 小时前
彭大帅的AI运维助手第 10 篇——K8s 集群探针升级记:从服务级到业务级
运维·kubernetes·aiops·彭大帅
考虑考虑7 小时前
nginx拦截url
运维·后端·nginx
速捷工控 PLC触摸屏还原程序9 小时前
欧姆龙NB上传密码忘了,换屏前怎么保留原程序?
运维·服务器·欧姆龙
方便面不加香菜9 小时前
Docker Volume -- 对照总结及综合实战案例操作演示
运维·docker·容器
爱勇宝9 小时前
SSL 证书别再手动续了:acme.sh + Let's Encrypt + 云厂商 DNS 全自动实战
运维·服务器
数据库小学妹11 小时前
数据库容量规划:四个数与扩容触发线
运维·数据库·后端
去码头整点薯条9813 小时前
NFS服务器
linux·运维·服务器
蜗牛一步步往上爬13 小时前
第一章 初识Linux shell
linux·运维·服务器
饿了吃洗衣凝珠14 小时前
DNS域名解析服务器
运维·服务器
新*15 小时前
Elasticsearch 索引别名入门:创建、路由、原子切换与几个常见误解
运维·后端·elasticsearch·索引别名