茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1671280 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
F09_365.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [轉貼]Let’s Encrypt 免費 SSL/TLS 憑證安裝

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]Let’s Encrypt 免費 SSL/TLS 憑證安裝

Let’s Encrypt免費SSL/TLS憑證安裝

使用HTTPS連線服務,幫網站加密。

2016年12月底,Google發佈消息:

From the end of January with Chrome 56, Chrome will mark HTTP sites that collect passwords or credit cards as non-secure.

網站的全面HTTPS化已經是趨勢,但以往想為網站加入 SSL 加密協定( HTTPS),必須支付一筆費用來申請憑證。現在有個名為 Let’s Encrypt 的數位憑證認證機構推出 免費 SSL/TLS 憑證服務。

Let’s Encrypt


Let’s Encrypt 憑證簽發為每三個月一次,也就是每 90 天必須更新(renew)一次。取得憑證的過程需要進主機安裝代理程式,代理程式就叫做 “letsencrypt”,是 Let’s Encrypt 官方软件 certbot 在 Ubuntu 16.04 上的名字。

在Ubuntu 16.04上安裝 Let’s Encrypt 和創建SSL

1. 安裝 letsencrypt

進入主機更新apt-get後安裝letsencrypt:

sudo apt-get install letsencrypt

2. 取得 SSL 證書

Step1: 開啟網路服務軟體 well-know 功能

執行指令

sudo vim /etc/nginx/sites-available/default

再 server 後面的大括號中寫入資料

location ~ /.well-known {
allow all;
}
}

用 nginx 的預設測試指令查看內容有沒有錯誤

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Step2: 重新啟動 nginx

sudo systemctl restart nginx

Step3: 製作 SSL 證書,並使用EMAIL註冊


var/www/html -d www.example.com
# 將/var/www/html換成app的根目錄位置,如果使用Capistrano自動化部署,path爲 /home/deploy/example/current/public;
# 將www.example.com換成自己的網域名稱

途中需輸入信箱,最後同意 Lets Encrypt 使用條款。

完成時會出現類似下面的訊息

/etc/letsencrypt/live/example.com/fullchain.pem. Your cert
will expire on 2017-08-06. To obtain a new version of the
certificate in the future, simply run Let's Encrypt again.
- If you like Let's Encrypt, please consider supporting our work by:
Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le

表示伺服器的 SSL Key會存到/etc/letsencrypt/live/example.com/這個位置,這個路徑之後會用到。

註:如果失敗超過5次會遭到封鎖 1小時


An unexpected error occurred:
There were too many requests of a given type :: Error creating new authz :: Too many invalid authorizations recently.
Please see the logfiles in /var/log/letsencrypt for more details.
We recently (April 2017) introduced a Failed Validation limit of 5 failures per account, per hostname, per hour. This limit will be higher on staging so you can use staging to debug connectivity problems.

製作安全性更高的 Diffie-Hellman

迪菲-赫爾曼密鑰交換是一種安全協定。它可以讓雙方在完全沒有對方任何預先資訊的條件下通過不安全信道建立起一個金鑰。這個金鑰可以在後續的通訊中作為對稱金鑰來加密通訊內容。

產生一個 2048bit 的 Diffie-Hellman:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

3. 調整 Nginx 的配置,讓網站受到 SSL 保護

Step1: 利用snippets讓Nginx方便載入設定。

在 /etc/nginx/snippets 目錄裡面建立 ssl-example.com.conf 檔案,example.com 換成自己的domain。

sudo vim /etc/nginx/snippets/ssl-example.com.conf

內容貼上:


ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# 將example.com換成自己的網域名稱

另外建立一個 ssl-params.conf 規範一些 SSL 的設定:

sudo vim /etc/nginx/snippets/ssl-params.conf

貼上 Cipherli.st 建議的 Nginx 設定,並在最後一行導入2048bit Diffie-Hellman:

https://cipherli.st/
# and https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
ssl_ecdh_curve secp384r1;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
ssl_dhparam /etc/ssl/certs/dhparam.pem;

Step2: 修改 Nginx 的設定檔案。

先備份default 檔案

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bak

修改default 檔案:

sudo vim /etc/nginx/sites-available/default

將以下內容加入server{}中:

# SSL configuration
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

include snippets/ssl-example.com.conf; # example.com換成正確檔案名稱
include snippets/ssl-params.conf;

內容是加入Listening Port 443 ,啓用 HTTP/2,以及將剛剛製作的2個檔案載入。接下來修改 nginx 的虛擬主機配置:

sudo vim /etc/nginx/sites-enabled/example.conf

listen 443 ssl http2; 加到檔案中。

$ sudo nginx -t 檢查設定是否正確,正確後重啓服務:

$ sudo systemctl restart nginx

利用 Qualys SSL Labs Report 查看我們網站的安全性是否可以順利拿到 A+ 的成績。

4. 自動更新憑證

letsencrypt 代理程式有提供自動更新的指令:

sudo letsencrypt renew
The following certs are not due for renewal yet:
/etc/letsencrypt/live/platform.loginyo.com/fullchain.pem (skipped)
No renewals were attempted.
# 還不需要更新時,不會執行。

利用crontab自動排程:

  • 更新憑證。
  • 重新加載網頁服務器。

30 2 * * 7 root /usr/bin/letsencrypt renew >> /var/log/le-renew.log
35 2 * * 7 root /bin/systemctl reload nginx

每個禮拜天的晚上2點30分更新憑證,然後2點35分的時候重新加載網頁服務器。

Mixed content 瀏覽器警告

安裝完之後可能會發現網站還是顯示爲不安全,瀏覽器的console會出現
Mixed Content 警告訊息。意思是說你在加密的 HTTPS 的網頁之中,使用到非加密的 HTTP 的資源,這個資源可能是 JavaScript、CSS、圖片或是 iframe (不包括超連結)。

解決方案是將有用到絕對網址 http:// 開頭的資源替換成 HTTPS。

Google Developer 網站的教學: Fixing mixed Content


原文出處:Let’s Encrypt免費SSL/TLS憑證安裝 – Dosmanthus – Medium
前一個主題 | 下一個主題 | | | |

討論串




Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|