溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

個(gè)人博客http轉(zhuǎn)https

發(fā)布時(shí)間:2020-04-10 19:15:16 來(lái)源:網(wǎng)絡(luò) 閱讀:5085 作者:lorysun 欄目:建站服務(wù)器

  搭建個(gè)人博客的時(shí)候,就看過(guò)一些免費(fèi)證書(shū)申請(qǐng)的文章,也瀏覽過(guò)一些使用Https的博客。使用Https要比Http安全很多,至少在國(guó)內(nèi)很普通的流量劫持***會(huì)減少很多。閑來(lái)無(wú)事,測(cè)試把自己的個(gè)人博客也升級(jí)到Https。

  使用Https加密首先就需要申請(qǐng)個(gè)人博客證書(shū),收費(fèi)的證書(shū)頒發(fā)機(jī)構(gòu)國(guó)內(nèi)和國(guó)外都有很多。個(gè)人博客推薦使用現(xiàn)在比較流行的Let's Encrypt。申請(qǐng)過(guò)程比較簡(jiǎn)單,使用官方自動(dòng)化腳本:

1、配置git環(huán)境:# yum install git

2、下載自動(dòng)化腳本到本地

# git clone https://github.com/certbot/certbot

# cd certbot

3、生成證書(shū)

./certbot-auto certonly --standalone --email loryxxx@hotmail.com -d iorisun.com -d www.iorisun.com

個(gè)人博客http轉(zhuǎn)https

將安裝以下軟件包

個(gè)人博客http轉(zhuǎn)https

安裝過(guò)程,需要手動(dòng)確認(rèn)是否安裝,輸入Y確認(rèn)。另外還需要接受官方協(xié)議,輸入A回車(chē)即可。

注意:申請(qǐng)時(shí),防火墻需要開(kāi)通https端口

# firewall-cmd --permanent --zone=public --add-service=https 

# firewall-cmd --reload

申請(qǐng)成功后,有以下提示:

個(gè)人博客http轉(zhuǎn)https

可通過(guò)tree命令查看:# tree /etc/letsencrypt/live/

個(gè)人博客http轉(zhuǎn)https

4、修改nginx配置文件

# vim /etc/nginx/conf.d/default.conf 

在Nginx配置文件中加入SSL參數(shù)定義,把http重定向到https

如下:修改和增加以下內(nèi)容(為避免升級(jí)nginx后主頁(yè)被修改,最好把index.php放在首位)

個(gè)人博客http轉(zhuǎn)https

重啟服務(wù)后,再打開(kāi)網(wǎng)站就可以看到綠色的小鎖了。

個(gè)人博客http轉(zhuǎn)https

5、設(shè)置證書(shū)自動(dòng)延期

Let's Encrypt的證書(shū)有效期只有90天,需要定期更新證書(shū):

通過(guò)crontab制定一個(gè)計(jì)劃任務(wù),每2個(gè)月(即1、3、5、7、9、11月15日凌晨2點(diǎn)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命令也可以(注:要先關(guān)閉nginx服務(wù)再運(yùn)行,否則會(huì)報(bào)錯(cuò))。

6、修改博客站點(diǎn)地址

個(gè)人博客http轉(zhuǎn)https

注意:需要同步修改圖片地址http為https(如修改數(shù)據(jù)庫(kù)等)


優(yōu)化Https安全性

1、生成dhparam.pem

# cd /etc/ssl/certs/

# openssl dhparam -out dhparam.pem 2048

個(gè)人博客http轉(zhuǎn)https

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=
生成備用證書(shū)指紋(官方備用):
# 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;


  配置完之后可以測(cè)試一下網(wǎng)站的安全級(jí)別:https://www.ssllabs.com/ssltest/

個(gè)人博客http轉(zhuǎn)https

參考: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


向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI