Let’s Encrypt簡介
官網:https://letsencrypt.org/java
Let’s Encrypt做爲一個公共且免費SSL的項目逐漸被廣大用戶傳播和使用,是由Mozilla、Cisco、Akamai、IdenTrust、EFF等組織人員發起,主要的目的也是爲了推動網站從HTTP向HTTPS過分的進程,目前已經有愈來愈多的商家加入和贊助支持。nginx
certbot簡介
官方客戶端 CertbotCertBot提供了不少命令來管理證書的獲取,更新,與撤銷,詳情可參閱官網。git
操做步驟
1.克隆certbot倉庫
sudo git clone github
https://github.com/certbot/ce...web
2. Nginx server配置域名驗證
`location ^~ /.well-known/acme-challenge/ {
default_type "text/plain";
root /opt/JAVA1024/CERT;
}api
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.letsencr... -a webroot --webroot-path=$DIR -d $DOMAINS`spa
4.使用證書, Nginx server配置
`listen 443;#let's encryptserver
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.letsencr... -a webroot --webroot-path=$DIR -d $DOMAINS`
7. 重啓服務器
nginx -s reload
訪問域名,效果展現: