使用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"
相关推荐
j7~1 分钟前
【Linux网络】四十六.《高级 IO (上篇)》-- 详解
linux·运维·网络
IT大白鼠18 分钟前
彭大帅的AI运维助手——自然语言管理 Linux 集群与网络设备——第 0 篇 · 导读:把 Linux 运维交给 AI,到底靠谱吗
linux·运维·人工智能
分布式存储与RustFS32 分钟前
自托管对象存储的三种 TLS 签发:自签、Let‘s Encrypt、内网 CA 的选择与轮换
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
Li-Yongjun1 小时前
fuser
运维
William Dawson1 小时前
kkFileView 内网 ARM 服务器全链路部署:从「找不到 office」到全绿通关(超详细排障实录)
运维·服务器
海宇数据1 小时前
零信任架构实战:基于海宇车型识别精准构建自动化违章处理网关
运维·人工智能·架构·自动化
xbzb1 小时前
Linux SELinux 安全加固与标签排错手册
linux·运维·安全
其实防守也摸鱼2 小时前
SQL注入实验笔记
android·运维·数据库·安全·oracle·自动化
江屿风2 小时前
【Linux系统】【从【收尾】缓冲区到【新开】磁盘块:一节课打通文件系统底层原理】流食般投喂
linux·运维·服务器·人工智能·笔记
曹牧2 小时前
Spring MVC : Controller 层URL划分
java·运维·服务器·前端