最近在升级交流学习社区, 觉得有必要升级成 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 验证方式一般需要由您的域名管理人员进行相关操作. 请按照您的证书订单中的进度提示, 在您的域名管理系统中进行相应配置.
选择 DNS 域名授权验证方式, 您需要到您的域名解析服务商 (如万网, 新网, DNSPod 等) 提供的系统中进行配置. 例如, 您的域名托管在阿里云, 则需要到云解析 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 模块
附注 2:nginx 的 https 服务配置
- # HTTPS server
- server {
- listen 443;
- server_name www.mwcxs.top;
- ssl on;
- root /home/Node.JS/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://www.cnblogs.com/chengxs/p/9862939.html