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;
        }
    
    }       
    

      

  • 相关阅读:
    NPOI操作Excel
    父窗口调用iframe子窗口方法
    js 全选全不选
    常用的几种 SQLServer 分页查询方式实现
    通用简单的 分页 SQL
    C#导出
    delphi xe firemonkey 调用VLC播放器播放视频
    Android版本和API Level对应关系
    Android开发之视频录制1
    Android上实现视频录制
  • 原文地址:https://www.cnblogs.com/weifeng1463/p/15691920.html
Copyright © 2011-2022 走看看