利用nginx,騰訊雲免費證書製做https

以前一直在研究,https怎麼弄。最近看到了騰訊雲提供的免費得ssl證書,尋思把網站弄成https。nginx

首先先去騰訊雲購買一個免費得證書。spring

點擊後填寫內容,springboot

而後下載證書bash

解壓證書就能夠看到,提供四種方式來修改https,咱們須要用到的是 Nginx包裏面的東西。服務器

證書到這裏就搞完了。session

而後說一下項目配置,本人網站項目是用springboot作的,端口號8888。網站

而後服務器安裝nginx,具體安裝細節就不細說了,不懂的就百度一下吧,特別簡單。須要說的就是nginx.conf配置:spa

##這裏是將http默認的80端口重定向到https
    server {
        listen       80;
        server_name  www.dalaoyang.cn;
        rewrite ^ https://$http_host$request_uri? permanent; 
    }
	
	##這裏是將默認請求https的443端口攔截
	##並請求轉發到http://127.0.0.1:8888/
    server {
        listen 443;
        server_name www.dalaoyang.cn;
        ssl on;     
         ssl_certificate 1_dalaoyang.cn_bundle.crt;
        ssl_certificate_key 2_dalaoyang.cn.key;
        ssl_session_timeout 5m;
        location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_set_header X-NginX-Proxy true;
               #你的項目端口號
            proxy_pass http://127.0.0.1:8888/;
            proxy_redirect off;
        }
    }
複製代碼

而後在網站上輸入www.dalaoyang.cn就能夠看到以下圖code

相關文章
相關標籤/搜索