前兩天作一個小程序,由於要審覈上線才發現微信規定的服務器請求接口是https的,因而乎就爲服務器升級html
1:購買SSL證書,能夠直接到阿里雲上買,由於我是阿里雲服務器,所在是在阿里雲上面買的免費版證書試試手nginx
2:下載證書配置服務器小程序
買了證書籤發完後,能夠根據阿里雲的開發文檔指導配置服務器
參考網址: https://help.aliyun.com/knowledge_detail/95505.html?spm=5176.2020520154.cas.9.1738U2tQU2tQb4微信
由於個人是Nginx服務器,我就簡單說一下Nginx服務器的配置session
在Nginx的安裝目錄下建立cert目錄,而且將下載的所有文件拷貝到cert目錄中。若是申請證書時是本身建立的CSR文件,請將對應的私鑰文件放到cert目錄下而且命名爲a.key;阿里雲
打開 Nginx 安裝目錄下 conf 目錄中的 nginx.conf 文件spa
server { listen 443; server_name localhost; ssl on; root html; index index.html index.htm; ssl_certificate cert/a.pem; ssl_certificate_key cert/a.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 html; index index.html index.htm; }
4:記得必定要重啓nginx服務器。執行:# /usr/local/nginx/sbin/nginx -s reload 重啓成功後你的網頁就會變成https訪問了。code
3:可是會出現一個問題,就是用戶直接屬於域名的話,它還會是訪問http,除非手動輸入https,這個時候就要監聽服務器的80端口,讓它跳轉到https,須要在nginx.conf 文件下加入如下代碼:server
server { listen 80; server_name localhost; rewrite ^(.*)$ https://$host$1 permanent; location / { root html; index index.html index.htm; } }
不是加在443端口的server裏面,而是有兩個server。
這樣再重啓Nginx服務器,用戶一輸入域名就會訪問到https了。