使用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"
相关推荐
文牧之1 分钟前
PostgreSQL的扩展 pgcrypto
运维·数据库·postgresql
白总Server1 分钟前
多智能体系统的中间件架构
linux·运维·服务器·中间件·ribbon·架构·github
浪裡遊2 小时前
跨域问题(Cross-Origin Problem)
linux·前端·vue.js·后端·https·sprint
2401_867021902 小时前
文件缓冲区(IO与文件 ·III)(linux/C)
linux·运维·服务器·c语言
刘某的Cloud2 小时前
rabbitmq常用命令
linux·运维·分布式·rabbitmq·系统
悄悄敲敲敲3 小时前
Linux:进程间通信->命名管道
linux·运维·服务器
io无心3 小时前
Docker绑定端口报错
运维·docker·容器
悄悄敲敲敲5 小时前
Linux:进程间通信->共享内存
linux·运维·服务器
绵绵细雨中的乡音6 小时前
Linux进程学习【环境变量】&&进程优先级
linux·运维·学习
天下·第二6 小时前
【Nginx】负载均衡配置详解
运维·nginx·负载均衡