一、申请 SSL 证书
各域名注册平台都提供证书申请,以官方申请为准,这里我以西部数码的SSL证书服务为例。
1、购买证书
注:西数申请顶级域名送www域名,如:cncsoft.cn 包含:cncsoft.cn和www.cncsoft.cn,因此只是网站用途,申请1个即可。


根据提示,购买完成。
2、域名解析记录添加验证
在域名管理 解析 中增加一个域名验证 TXT 记录,供证书验证。

解析添加后,等待几分钟,再提示证书方审核即可。
3、下载证书
证书颁发完成后,点击:详情,进入证书下载页面


根据WEB服务下载相应的证书。

二、Nginx 部署 SSL 证书
1、上传到网站服务器
在网站目录,新建 cert 目录,将解压后的证书文件上传到网站服务器。

2、修改 nginx.conf 文件,支持 443 SSL
# HTTP 重定向到 HTTPS
server {
listen 80;
server_name 118.x.x.x; # 服务器IP地址
return 301 https://$host$request_uri;
}
# HTTPS 服务器配置
server {
listen 443 ssl;
server_name 118.x.x.x; # 替换为您的服务器IP或域名
root /var/www/cncsoft/frontend;
index index.html;
# SSL 配置
ssl_certificate /var/www/cncsoft/cert/cncsoft.cn.crt;
ssl_certificate_key /var/www/cncsoft/cert/cncsoft.cn.key;
# 安全配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ALL:!DH:!EXPORT:!RC4:+HIGH:+MEDIUM:!LOW:!aNULL:!eNULL;
# 其它根据业务需要自行配置...
}
3、检查参数文件并重启Nginx
- 测试配置:
[root@iZbp15cwtzpn4g6oi14m6rZ sbin]# ./nginx -t
nginx: the configuration file /var/www/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /var/www/nginx/conf/nginx.conf test is successful
- 重载配置:
[root@iZbp15cwtzpn4g6oi14m6rZ sbin]# ./nginx -s reload
- 重启Nginx:
[root@iZbp15cwtzpn4g6oi14m6rZ sbin]# ./nginx -s stop
[root@iZbp15cwtzpn4g6oi14m6rZ sbin]# ./nginx
三、验证证书结果
打开网站对2个解析进行验证,如:
Nginx配置SSL证书443端口指南
4191

被折叠的 条评论
为什么被折叠?



