使用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. 使用certbot申请https通配符证书【阿里云篇】

    2024-03-29 01:40:04       39 阅读
  2. Linux:使用ssl加密网站https

    2024-03-29 01:40:04       15 阅读

最近更新

  1. Android IdleHandler源码分析

    2024-03-29 01:40:04       0 阅读
  2. docker-1

    docker-1

    2024-03-29 01:40:04      0 阅读
  3. Git批量删除本地h和远程分支说明

    2024-03-29 01:40:04       0 阅读
  4. mvccaa

    2024-03-29 01:40:04       1 阅读
  5. Linux 常用指令详解

    2024-03-29 01:40:04       1 阅读
  6. 第2章 源码编译构建LAMP

    2024-03-29 01:40:04       1 阅读
  7. 数据库doris中的tablet底层解析

    2024-03-29 01:40:04       1 阅读
  8. 使用Python threading模块创建多线程程序

    2024-03-29 01:40:04       1 阅读
  9. 探索数据的奥秘:sklearn中的聚类分析技术

    2024-03-29 01:40:04       1 阅读

热门阅读

  1. 【GameFramework框架内置模块】16、配置(Setting)

    2024-03-29 01:40:04       23 阅读
  2. math模块篇(六)

    2024-03-29 01:40:04       15 阅读
  3. python的logger日志的封装模板

    2024-03-29 01:40:04       22 阅读
  4. 团队建设与管理案例分析题

    2024-03-29 01:40:04       20 阅读
  5. vue 事件处理

    2024-03-29 01:40:04       24 阅读
  6. Zigbee技术在智能农业领域的应用研究

    2024-03-29 01:40:04       25 阅读