最近在升級交流學習社區,覺得有必要升級成https.以下是自己在升級中記錄。
以下包括以下部分:
一、阿里雲免費購買SSL證書
1、自己在阿里雲申請了免費的,然后自己支付0元,購買了SSL證書
2、我選擇DNS驗證
3、在SSL證書中,下載cert證書,然后放到nginx服務器上
二、nginx無縫升級https
4、查看nginx是否支持ssl
5、配置ssl模塊
6、重新編譯一下
7、因為這次是升級nginx,所以不需要執行 make install,首先備份原nginx執行腳本
8、把新編譯的nginx執行腳本拷貝到相應的目錄下:’
9、最后進行平滑升級
10、再次檢查nginx是否有https模塊
11、展示一下https網站站點,https://www.mwcxs.top/
附注1:nginx配置SSL報錯問題,ssl on報錯
附注2:nginx的https服務配置
1、自己在阿里雲申請了免費的,然后自己支付0元,購買了SSL證書

2、我選擇DNS驗證,因為域名是自己的。
DNS驗證方式一般需要由您的域名管理人員進行相關操作。請按照您的證書訂單中的進度提示,在您的域名管理系統中進行相應配置。
3、在SSL證書中,下載cert證書,然后放到nginx服務器上

4、查看nginx是否支持ssl:
./nginx -V

查看 configure arguments 信息中是否包含 -with-http_ssl_module 字樣
5、配置ssl模塊
找到之前安裝 Nginx 時的解壓目錄,配置ssl模塊:
./configure --with-http_ssl_module

6、重新編譯一下
在解壓目錄執行make
make

7、因為這次是升級nginx,所以不需要執行 make install,首先備份原nginx執行腳本:
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old

8、把新編譯的nginx執行腳本拷貝到相應的目錄下:
cd objs
cp nginx /usr/local/nginx/sbin/


9、最后進行平滑升級
cd ..
make upgrade

10、再次檢查nginx是否有https模塊

11、展示一下https網站站點,https://www.mwcxs.top/

附注1:nginx配置SSL報錯問題,ssl on報錯
啟動報錯(錯誤信息:nginx: [emerg] the "ssl" parameter requires ngx_http_ssl_module in /home/soft/nginx/conf/nginx.conf:76)
需要配置模塊ssl模塊 --with-http_ssl_modul,請查看本文的第二部分:2、配置ssl模塊
nginx: [emerg] the "http2" parameter requires ngx_http_v2_module in /usr/local/nginx/conf/nginx.conf:88
需要配置--with-http_v2_module 這便是我們添加的步驟5、配置ssl模塊這塊重新配置。
具體可以如下:
./configure --with-http_ssl_module --with-http_v2_module
這樣才算安裝了上述的兩個模塊。
附注2:nginx的https服務配置
# HTTPS server server { listen 443; server_name www.mwcxs.top; ssl on; root /home/nodejs/liblog/www; index index.js index.html index.htm; ssl_certificate /usr/local/nginx/cert/15420110408020120565539868.crt; ssl_certificate_key /usr/local/nginx/cert/15420110408020120565539868.key; ssl_session_cache shared:SSL:1m; 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; if ( -f $request_filename/index.html ){ rewrite (.*) $1/index.html break; } if ( !-f $request_filename ){ rewrite (.*) /index.js; } location / { proxy_http_version 1.1; proxy_set_header Connection ""; 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_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://learning_community_node$request_uri; proxy_redirect off; } location = /production.js { deny all; } location = /testing.js { deny all; } location ~ /static/ { etag on; expires max; } }
server { listen 80; server_name www.mwcxs.top mwcxs.top; return 301 https://$server_name$request_uri; }
注:return 301 https://$server_name$request_uri;用來把http轉換成https。
歡迎關注:https://github.com/saucxs/nodeJSBlog ,歡迎fork和start
