標籤:dex com 粘貼 服務 share uos ast ble 效能
2016-10-28 轉載請註明出處:http://daodaoliang.com/
作者: daodaoliang版本: V1.0.1郵箱: [email protected]
參考連結: 這裡 和 這裡 和 官方文檔
1. 製作伺服器憑證
伺服器CA私密金鑰:
openssl genrsa -des3 -out ca.key 2048
製作解密後的CA私密金鑰(一般無此必要):
openssl rsa -in ca.key -out ca_decrypted.key
ca.crt CA根憑證(公開金鑰):
openssl req -new -x509 -days 7305 -key ca.key -out ca.crt
2. 製作產生網站的認證並用CA簽名認證
在這裡,假設網站網域名稱為 www.example.com
產生 www.example.com 認證私密金鑰:
openssl genrsa -des3 -out www.example.com.pem 1024
製作解密後的 www.example.com 認證私密金鑰:
openssl rsa -in www.example.com.pem -out www.example.com.key
產生簽章要求:
openssl req -new -key www.example.com.pem -out www.example.com.csr
在common name中填入網站網域名稱,如 www.example.com 即可產生改網站的認證,同時也可以使用泛網域名稱如 *.example.com 來產生所有次層網域可用的網站認證。
用CA進行簽名:
openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in www.example.com.csr -out www.example.com.crt
其中,policy參數允許簽名的CA和網站認證可以有不同的國家、地名等資訊,days參數則是簽名時限。
如果在執行簽名命令時,出現“I am unable to access the ../../CA/newcerts directory”
修改/etc/pki/tls/openssl.cnf中“dir = ./CA”
然後:
mkdir -p CA/newcertstouch CA/index.txttouch CA/serialecho "01" > CA/serial
再重新執行簽名命令。
最後,把ca.crt的內容粘貼到 www.example.com.crt 後面。這個比較重要!因為不這樣做,可能會有某些瀏覽器不支援。
好了,現在https需要到的網站私密金鑰 www.example.com.key 和網站認證 www.example.com.crt 都準備完畢。接下來開始佈建服務端。
3. 配置nginx
新開一個虛擬機器主機,並在server{}段中設定:
listen 443;ssl on;ssl_certificate /path/to/www.example.com.crt;ssl_certificate_key /path/to/www.example.com.key;
其中的路徑是剛剛產生的網站認證的路徑。
然後使用一下命令檢測配置和重新載入nginx:
檢測配置:nginx -t重新載入:nginx -s reload
4. 最佳化nginx配置
https和http共存:
server { listen 80; listen 443 ssl; server_name zou.lu; root /var/www/html; #ssl on; //這行必須要注釋掉 ssl_certificate /usr/local/nginx/conf/zou_lu.crt; ssl_certificate_key /usr/local/nginx/conf/zoulukey.pem; }
最佳化效能:
在http{}中加入:
ssl_session_cache shared:SSL:10m;ssl_session_timeout 10m;
據官方文檔所述,cache中的1m可以存放4000個session。
在配置https的虛擬機器主機server{}中加入:
keepalive_timeout 70;
PS:常見錯誤:
| 有時候,會發現,在phpMyAdmin等程式登入後會錯誤地跳轉http的問題。解決方案是定位至“location ~ .*.(php |
php5)?${}”在include fcgi.conf;或者在fastcgi_param配置後面加上: |
fastcgi_param HTTPS on;fastcgi_param HTTP_SCHEME https;
最新最早最熱
http://daodaoliang.com/blog/2016/10/28/nginx%E9%85%8D%E7%BD%AEhttps%E5%B9%B6%E8%87%AA%E7%AD%BE%E5%90%8D%E8%AF%81%E4%B9%A6.html
nginx 配置https並自我簽署憑證