zoukankan      html  css  js  c++  java
  • 使用Let's Encrypt + Nginx生成免费HTTPS证书

    Let’s Encrypt简介

    官网:https://letsencrypt.org/

    Let’s Encrypt作为一个公共且免费SSL的项目逐渐被广大用户传播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等组织人员发起,主要的目的也是为了推进网站从HTTP向HTTPS过度的进程,目前已经有越来越多的商家加入和赞助支持。

    certbot简介

    官方客户端 CertbotCertBot提供了很多命令来管理证书的获取,更新,与撤销,详情可参阅官网。

    操作步骤

    1.克隆certbot仓库

    sudo git clone 

    https://github.com/certbot/certbot/opt/letsencrypt/opt/letsencrypt/letsencrypt-auto

    2. Nginx server配置域名验证

    location ^~ /.well-known/acme-challenge/ {
    
         default_type "text/plain";
    
        root  /opt/JAVA1024/CERT;
    
    }
    
     
    
    location = /.well-known/acme-challenge/ {
    
       return 404;
    
    }
    

      

    3.使用certbot生成证书

    export DOMAINS="java1024.club,m.java1024.club"export DIR=/opt/JAVA1024/CERT
    
    /opt/letsencrypt/letsencrypt-auto certonly --server https://acme-v01.api.letsencrypt.org/directory -a webroot --webroot-path=$DIR -d $DOMAINS
    

      

    4.使用证书, Nginx server配置

    listen 443;#let's encrypt
    
    ssl_certificate /etc/letsencrypt/live/java1024.club/fullchain.pem;
    
    ssl_certificate_key  /etc/letsencrypt/live/java1024.club/privkey.pem;
    

      

    5.创建自动检查更新脚本,并加入crontab

    crontab 是用来定期检查证书有效期。

    #!/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 1fi
    
    nginx -t && nginx -s reload

    加入定时任务

    sudo crontab -e

    @daily /mnt/crontab_scrpit/renew_certs.sh

    6.更改域名信息

    export DOMAINS="java1024.club,m.java1024.club,java1024.com"
    
    export DIR=/opt/JAVA1024/CERT
    
    /opt/letsencrypt/letsencrypt-auto certonly --server https://acme-v01.api.letsencrypt.org/directory -a webroot --webroot-path=$DIR -d $DOMAINS

    7. 重启服务器

    nginx -s reload

    访问域名,效果展示:

     
  • 相关阅读:
    Resource Path Location Type Target runtime Apache Tomcat v6.0 is not defined已解决
    项目跳转白名单防止其他系统随意跳转到本系统过滤器实现
    页面跳转的方式Redirect跳转机制:
    总结一下在ASP.NET中开发网站的一般步骤
    总结asp控件的重要属性
    页面跳转
    ASP.NET中的Image和ImageButton控件
    页面跳转的方式
    总结基本概念
    总结asp标准控件的重要属性
  • 原文地址:https://www.cnblogs.com/xueSpring/p/12689869.html
Copyright © 2011-2022 走看看