在阿里雲服務器上使用Nginx部署https協議的網站


前寫過一篇文章是在阿里雲服務器上用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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM