zoukankan      html  css  js  c++  java
  • Let’s Encrypt配置ssl证书自动更新

    配置基本的Nginx设置:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  yourwebsite.com;
    
        location ^~ /.well-known/acme-challenge/ {
           default_type "text/plain";
           root     /var/www/letsencrypt;
        }
    
        location = /.well-known/acme-challenge/ {
           return 404;
        }
        ... 其他配置,例如
        location / {
          proxy_pass http://localhost:8080;
        }
    }
    

    这里location配置了一个/.well-known/acme-challenge/路径,里面host了简单文件,我这里host了一个简单的html文件。原因是你必须证明,你拥有所请求的证书的域名。因为 Let’s Encrypt要求你host一些文件。

    证书90天过期

    Let’s Encrypt证书会在90天后过期,需要配置脚本自动更新证书。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    #!/bin/sh
    # This script renews all the Let's Encrypt certificates with a validity < 30 days
    
    if ! /opt/letsencrypt/letsencrypt-auto renew > /var/log/letsencrypt/renew.log 2>&1 ; then
        echo Automated renewal failed:
        cat /var/log/letsencrypt/renew.log
        exit 1
    fi
    nginx -t && nginx -s reload

    示例配置:

    server {
        server_name   www.domain.com domain.com;
    
    
    
        listen 443 ssl; 
        ssl_certificate /etc/letsencrypt/live/www.domain.com/fullchain.pem; 
        ssl_certificate_key /etc/letsencrypt/live/www.domain.com/privkey.pem; 
        include /etc/letsencrypt/options-ssl-nginx.conf; 
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; 
    
        location / {
               proxy_pass      https://shops.domain.com/;
               proxy_set_header  Host $host;
                  
                   }
    
        location ^~ /.well-known/acme-challenge/ {
           default_type "text/plain";
           root     /usr/share/nginx/html;
        }
    
        location = /.well-known/acme-challenge/ {
           return 404;
        }
    
    }       
    

      

  • 相关阅读:
    【URAL 1004】 floyd最小环
    【UVA 10881】 经典模拟题
    【HDU 1541】 树状数组(入门题)
    【HDU 4000】 树状数组
    【HDU 3391 && HDU 4431】 dfs+模拟
    【HDU 1058 & HDU 3199 类似丑数】 简单DP思想
    Acdream原创群赛3(部分题解)
    vfor实现双层循环嵌套
    vue获取当前时间并实时刷新时间
    vue+element ui实现左侧导航栏动态路由跳转
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/15691920.html
Copyright © 2011-2022 走看看