Let's Encrypt: 為CentOS/RHEL 7下的nginx安裝https支持-具體案例


環境說明:

centos 7 nginx 1.10.2 

前期准備

軟件安裝

yum install -y epel-release yum install -y certbot 

創建目錄及鏈接

方法1:在網站根目錄下創建一個.well-known的目錄 方法2: mkdir -p /usr/local/nginx/cert/.well-known ln -s /usr/local/nginx/cert/.well-known /data/www/example.com/.well-known ln -s /usr/local/nginx/cert/.well-known /data/www/test.example.com/.well-known 

命令執行

certbot certonly --webroot -w /usr/local/nginx/cert -d example.com -d test.example.com 根據提示進行操作,一般可以正常生產證書文件。 證書文件的目錄存放在: '/etc/letsencrypt/live/example.com/' 會有4個文件: cert.pem chain.pem fullchain.pem privkey.pem 特別要注意,這條命令只會將生成的證書放在這個目錄,不會有一個/etc/letsencrypt/live/test.example.com/目錄,test.example.com的證書和example.com的證書放在一起了,具體看后面的nginx配置。 

nginx配置

server { listen 443 ssl http2; server_name example.com; index index.html index.htm index.php; root /data/www/example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; access_log off; } server { listen 443 ssl http2; server_name test.example.com; index index.html index.htm index.php; root /data/www/test.example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH"; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; access_log off; } 

定期更新


crontab -e # 新增如下定時任務 10 6 * * * /bin/certbot renew --quiet &>/dev/null Let's Encrypt 的證書有效期為90天,如果證書的有效期大於30天,則上面命令不會真的去更新證書的。 

https測試

在瀏覽器輸入 https://example.com 網址進行驗證,一般Chrome會有一個綠色的鎖以及Secure標示。

 

最后如果覺得所講的東西能夠幫助到你,並且希望了解更多的知識,進行更詳細的深入的學習,歡迎加群632109190進行討論和學習。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM