標籤:其他 ati dig ica secure cgi unit wiki []
什麼是 HTTPS?#
HTTPS(全稱:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全為目標的HTTP通道,簡單講是HTTP的安全版。
更多基本介紹請查閱:
- 數位簽章是什嗎?(圖文並茂, 清晰易懂, 重點推薦)
- HTTPS on WIKI
- 密碼學筆記
- SSL 與數位憑證
- 另一個圖文並茂的筆記, 供參考 --> 泛網域名稱ssl認證搭建全攻略
需要弄清楚的幾個問題:
- HTTPS 和 SSL 的關係與基本技術實現;
- SSL 憑證的類型;
- 什麼是憑證授權單位, 為什麼會存在;
- 認證認證等級, DV, OV 和 EV 各自的意思;
- 什麼是
泛網域名稱 SSL 憑證 (Wildcard Domain SSL Certificates)
操作步驟#
一個大概流程如下:
- 購買前準備 - 伺服器產生 csr 和 key 檔案;
- 購買認證 - 利用上面產生的 csr 檔案去購買認證;
- 購買成功後的認證有兩個, 一個是網域名稱認證, 一個是鏈認證, 把他們倆按照順序合并為 crt 檔案;
- Nginx 下配置 key 和 crt 檔案, 並做安全調優.
購買認證前的準備#1. 產生認證 CSR 和 KEY#
mkdir -p /etc/nginx/ssl/phphubcd /etc/nginx/ssl/phphub
2. 產生 orig 檔案#
openssl genrsa -out phphub.orig 2048
3. 產生 csr 檔案#
運行
openssl req -new -key phphub.orig -out phphub.csr
輸出, 需要填寫內容:
You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter ‘.‘, the field will be left blank.-----Country Name (2 letter code) [AU]:CNState or Province Name (full name) [Some-State]:BeiJingLocality Name (eg, city) []:BeiJingOrganization Name (eg, company) [Internet Widgits Pty Ltd]:The EST GroupOrganizational Unit Name (eg, section) []:DevCommon Name (e.g. server FQDN or YOUR name) []:*.phphub.org // ----------注意這個地方要認真填寫Email Address []: emailaddress @ gmail.comPlease enter the following ‘extra‘ attributesto be sent with your certificate requestA challenge password []: ----------注意不填寫----------An optional company name []: ----------注意不填寫----------
4. 產生 private key 檔案#
openssl rsa -in phphub.orig -out phphub.key
至此檔案夾裡面有 三個檔案:
[email protected]:/etc/nginx/ssl/phphub# tree.├── ikbcity.csr├── phphub.key└── phphub.orig
購買認證#
購買細節這裡省去, 需要注意的是要認準比較權威的認證機構購買...
購買成功後會給你發兩個認證 server.crt 和 server.intermediate.crt, 產生最終的 server.chained.crt
cat server.crt server.intermediate.crt > phphub.crt
此檔案就可以和上面產生的 key 檔案一起用來配置 nginx 了:
ssl_certificate /etc/nginx/ssl/phphub/phphub.crt;ssl_certificate_key /etc/nginx/ssl/phphub/phphub.key;
配置安全的 Ngxin#
連結:
- Best nginx configuration for security
- Nginx config on Gits
- Top 20 Nginx WebServer Best Security Practices
- SSL Server Test -- 安全性測試工具
強制使用 HTTPS#
server { listen 80; listen 443 ssl; server_name example.com; if ($scheme = http) { return 301 https://$server_name$request_uri; } ....}
去除 Nginx 的
X-Powered-By
header#
fastcgi_hide_header X-Powered-By;
去除 nginx 版本#
server_tokens off;
不允許被 iframe 載入#
add_header X-Frame-Options SAMEORIGIN;
其他參照此 Gits: Nginx config on Gits
靜態內容#
一般都會出現 cdn 伺服器無法訪問 https 原始伺服器的問題, 可以使用專門的網域名稱 static.phphub.org
來解決, 此網域名稱專門用來輸送靜態內容:
server { listen 80; server_name static.phphub.org; root /var/www/phphub/public; location ~* \.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|exe|html|htm|txt|css|js) { add_header Cache-Control public; add_header Cache-Control must-revalidate; expires 7d; } location / { deny all; }}
結語#
可以利用 SSL Server Test -- 安全性測試工具 去測試下你的 HTTPS 是否夠安全.
附上 phphub 的 test
Nginx 下部署 HTTPS 與安全調優