ACME-TINY制作免费的HTTPS证书

前言

虽然实现了https的环境搭建,用到付费的CA认证机构,然而身边确实有很多声音在建议这免费的https SSL证书,于是乎自己真正搭建尝试了一下免费的https的搭建过程,并且阐述自己的理解

4种不同的证书

企业级别:EV(Extended Validation)、OV(Organization Validation)
个人级别:IV(Identity Validation)、DV(Domain Validation)

其中 EV、OV、IV 需要付费,免费的证书安全认证级别一般比较低,不显示单位名称,不能证明网站的真实身份,仅起到加密传输信息的作用,适合个人网站或非电商网站。注:此低端SSL已经被国外各种欺诈网站滥用。不过此类证书的CA认证效率确实很高,因为在提交CA认证的时候只需要提供域名和需要验证的邮箱地址.

基于acme-tiny申请可用的免费ssl证书

github acme-tiny项目说明文档链接:
https://github.com/diafygi/acme-tiny

中文说明

此脚本需要python和openssl的支持,没有的话请自行安装,另外请自行创建一个工作目录

step1:创建一个 Let's Encrypt账户私钥,以便让其识别你的身份
openssl genrsa 4096 > account.key

step2:创建域名证书请求文件(CSR)
openssl genrsa 4096 > domain.key
openssl req -new -sha256 -key domain.key -subj "/" -reqexts SAN -config <(cat /usr/local/ssl/openssl.cnf <(printf "[SAN]\nsubjectAltName=DNS:[donmain.com]")) > [domain].csr

step3:配置验证域名所有权的服务,创建验证目录
mkdir -p /home/wwwroot/challenges/


step4:配置一个HTTP服务让LETSENCRYPT能下载验证文件
server {
    listen 80;
    server_name yoursite.com www.yoursite.com;

    location /.well-known/acme-challenge/ {
        alias /var/www/challenges/;
        try_files $uri =404;
    }
...the rest of your config
}


step5:获取签名证书
python acme_tiny.py --account-key ./account.key --csr ./domain.csr --acme-dir /var/www/challenges/ > ./signed.crt

step6:转化crt到pem文件
wget -O - https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > intermediate.pem
cat signed.crt intermediate.pem > chained.pem

step7:配置nginx
    listen       443 ssl;
    server_name  [监听域名];
    ssl_certificate      /httpsfile/chained.pem;
    ssl_certificate_key  /httpsfile/domain.key;
    ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    location / {
         proxy_pass   http://127.0.0.1:8080/;
         proxy_redirect off;
         proxy_set_header X-Real-IP $remote_addr;
         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }



 step8:脚本覆盖策略
 基于此证书3个月有效期,此外建立一个脚本进行一个证书覆盖操作。(所以此方法建议测试环境验证https环境,并不建议应用到生产环境)
vi ~/letsencrypt/renew_cert.sh
#!/usr/bin/sh
python /path/to/acme_tiny.py --account-key /path/to/account.key --csr /path/to/domain.csr --acme-dir /var/www/challenges/ > /tmp/signed.crt || exit
wget -O - https://letsencrypt.org/certs/lets-encrypt-x3-cross-signed.pem > intermediate.pem
cat /tmp/signed.crt intermediate.pem > /path/to/chained.pem
service nginx reload
chmod +x renew_cert.sh

加入crontab
0 0 1 * * ~/letsencrypt/renew_cert.sh 2>> /var/log/acme_tiny.log

猜你喜欢

转载自blog.csdn.net/zhang6622056/article/details/53738450