前寫過一篇文章是在阿里雲服務器上用Apache切換https協議:將博客遷移阿里雲並且切換成https解析的過程
這一次,換成使用Nginx來部署,相比之下,比Apache的配置要簡單一些
如何申請SSL證書就按下不表了,非常簡單,目前阿里雲和騰訊雲都免費提供一年的證書服務,區別就是騰訊雲不需要域名在騰訊,而阿里雲只有域名在阿里旗下才提供。
申請域名證書成功后,下載壓縮包,一定要選擇Nginx的證書類型,解壓后得到一個key文件一個pem文件,將這兩個文件上傳到服務器的root目錄

然后打開nginx配置文件
vim /etc/nginx/conf.d/default.conf
同時添加http和https的協議配置,需要注意的是,http需要阿里雲安全協議暴露80端口,https需要阿里雲安全協議暴露443端口
server { listen 80; server_name m9u.cn; #這一步是http重定向到https,也可以不寫 rewrite ^(.*)$ https://${server_name}$1 permanent; access_log /root/md_vue_access.log; error_log /root/md_vue_error.log; client_max_body_size 75M; location / { root /root/fast_vue; index index.html; try_files $uri $uri/ /index.html; } error_log /root/fast_vue/error.log error; } server { listen 443; server_name m9u.cn; ssl on; ssl_certificate /root/2238250_m9u.cn.pem; ssl_certificate_key /root/2238250_m9u.cn.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root /root/fast_vue; index index.html; try_files $uri $uri/ /index.html; } }
重啟nginx
systemctl restart nginx.service
使用https//訪問
沒有問題,如果配置了重定向的話,那么訪問http的內容將會自動301重定向到https,增加了安全等級
有興趣的可以訪問我的私人網站:https://v7d.cn
