您好,登錄后才能下訂單哦!
搭建個人博客的時候,就看過一些免費證書申請的文章,也瀏覽過一些使用Https的博客。使用Https要比Http安全很多,至少在國內很普通的流量劫持***會減少很多。閑來無事,測試把自己的個人博客也升級到Https。
使用Https加密首先就需要申請個人博客證書,收費的證書頒發機構國內和國外都有很多。個人博客推薦使用現在比較流行的Let's Encrypt。申請過程比較簡單,使用官方自動化腳本:
1、配置git環境:# yum install git
2、下載自動化腳本到本地
# git clone https://github.com/certbot/certbot
# cd certbot
3、生成證書
./certbot-auto certonly --standalone --email loryxxx@hotmail.com -d iorisun.com -d www.iorisun.com
將安裝以下軟件包
安裝過程,需要手動確認是否安裝,輸入Y確認。另外還需要接受官方協議,輸入A回車即可。
注意:申請時,防火墻需要開通https端口
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload
申請成功后,有以下提示:
可通過tree命令查看:# tree /etc/letsencrypt/live/
4、修改nginx配置文件
# vim /etc/nginx/conf.d/default.conf
在Nginx配置文件中加入SSL參數定義,把http重定向到https
如下:修改和增加以下內容(為避免升級nginx后主頁被修改,最好把index.php放在首位)
重啟服務后,再打開網站就可以看到綠色的小鎖了。
5、設置證書自動延期
Let's Encrypt的證書有效期只有90天,需要定期更新證書:
通過crontab制定一個計劃任務,每2個月(即1、3、5、7、9、11月15日凌晨2點0分)更新一次。
0 2 15 */2 * root /root/certbot/certbot-auto renew --standalone --pre-hook "service nginx stop" --post-hook "service nginx start" --force-renewal
或者使用./certbot-auto renew -v命令也可以(注:要先關閉nginx服務再運行,否則會報錯)。
6、修改博客站點地址
注意:需要同步修改圖片地址http為https(如修改數據庫等)
優化Https安全性:
1、生成dhparam.pem
# cd /etc/ssl/certs/
# openssl dhparam -out dhparam.pem 2048
2、生成HTTP Public Key Pinning(https://developer.mozilla.org/en-US/docs/Web/HTTP/Public_Key_Pinning)
# cd /etc/letsencrypt/live/iorisun.com/ # openssl rsa -in privkey.pem -outform der -pubout | openssl dgst -sha256 -binary | openssl enc -base64 writing RSA key 9rcncxVnzws62MPkX5nUJPKs5jAGAhnxeqANv0Hx7Vo= 或者: # openssl s_client -servername www.iorisun.com -connect www.iorisun.com:443 | openssl x509 -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64 depth=2 O = Digital Signature Trust Co., CN = DST Root CA X3 verify return:1 depth=1 C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3 verify return:1 depth=0 CN = iorisun.com verify return:1 writing RSA key 9rcncxVnzws62MPkX5nUJPKs5jAGAhnxeqANv0Hx7Vo= # openssl x509 -in chain.pem -pubkey -noout | openssl rsa -pubin -outform der | openssl dgst -sha256 -binary | openssl enc -base64 writing RSA key YLh2dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg= 生成備用證書指紋(官方備用): # curl https://letsencrypt.org/certs/lets-encrypt-x4-cross-signed.pem | openssl x509 -pubkey | openssl pkey -pubin -outform der | openssl dgst -sha256 -binary | base64 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 1647 100 1647 0 0 1968 0 --:--:-- --:--:-- --:--:-- 1967 sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis=
3、修改nginx配置文件:
# vim /etc/nginx/conf.d/default.conf server { listen 80; listen 443 ssl http2; server_name www.iorisun.com iorisun.com; root /usr/share/nginx/html/; index index.html index.php index.htm; if ($scheme = http) { return 301 https://$server_name$request_uri; } ssl_certificate /etc/letsencrypt/live/iorisun.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/iorisun.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4"; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; ssl_session_tickets off; ssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/letsencrypt/live/iorisun.com/chain.pem; ssl_dhparam /etc/ssl/certs/dhparam.pem; server_tokens off; resolver 8.8.4.4 8.8.8.8 valid=300s; resolver_timeout 10s; fastcgi_hide_header X-Powered-By; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload"; add_header Public-Key-Pins 'pin-sha256="9rcncxVnzws62MPkX5nUJPKs5jAGAhnxeqANv0Hx7Vo="; pin-sha256="YLh2dUR9y6Kja30RrAn7JKnbQG/uEtLMkBgFF2Fuihg="; pin-sha256="sRHdihwgkaib1P1gxX8HFszlD+7/gTfNvuAybgLPNis="; max-age=2592000; includeSubDomains'; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff;
配置完之后可以測試一下網站的安全級別:https://www.ssllabs.com/ssltest/
參考:https://blog.kuoruan.com/71.html
https://imququ.com/post/http-public-key-pinning.html
https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
https://ithenrik.com/blog/posts/activating-http-public-key-pinning-hpkp-on-lets-encrypt
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。