最近突然好多朋友要弄全站https,特意也整理了一下設(shè)置的方法
一、準備證書
首先科普一下SSL證書類型
按審核方式分類:
1.域名驗證DV SSL證書
2.企業(yè)驗證OV SSL證書
3.企業(yè)增強/擴展驗證EV SSL證書
按照功能分類
1.多域名 UCC/SAN SSL證書
2.強加密SGC SSL證書
3.通配符Wildcard SSL證書
4.代碼簽名Code Signing SSL證書
申請證書過期不同代理商都不一樣寝受,自己領(lǐng)悟去吧寒匙,實驗使用的是阿里云申請的免費DV SSL證書,只需要免費購買呻率,填補一下資料即可硬毕。
二、配置Nginx
1.將下載的ssl證書上傳到服務(wù)器
2.#mkdir /opt/nginx/conf/key
將對應(yīng)server配置為如下
server {
server_name? test.test.cn;
access_log? logs/host.access.log? main;
listen 80;
listen 443 ssl;##開放兩個端口為了兼容http
ssl_certificate? /opt/nginx/conf/key/test.test.cn.pem;
ssl_certificate_key? /opt/nginx/conf/key/test.test.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 / {
proxy_pass? http://upstream_group;
proxy_set_header Host? $http_host;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size? 100m;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'POST, GET, OPTIONS,PUT,DELETE';
add_header 'Access-Control-Allow-Headers' '*,token';
}
}
這樣既可開啟https礼仗。
三吐咳、設(shè)置強制http跳轉(zhuǎn)https
1.雖然前面已經(jīng)實現(xiàn)了https,但是你回發(fā)現(xiàn)登錄后還是跳轉(zhuǎn)回http元践,這時候需要開啟全站https的話挪丢,則需要將http請求強制轉(zhuǎn)為https
加入如下配置
if ($server_port = 80) {
return 301 https://$server_name$request_uri;
}