一、通过openssl自制SSL CA证书
找一台linux机器,按如下步骤执行:
1、生成CA私钥文件myCA.key,需要设置CA私钥密码
#openssl genrsa -des3 -out myCA.key 2048
2、生成CA证书myCA.crt,需要验证CA私钥密码
#openssl req -x509 -new -nodes -key myCA.key -sha256 -days 36500 -out myCA.crt -subj “/C=CN/ST=ca-province/L=ca-city/O=ca-org/OU=ca-group/CN=ca-domin”
3、生成的CA证书可直接拷贝至客户端双击安装(安装完成后需求重启浏览器)
二、通过openssl 生成服务器证书
1、生成服务器私钥文件server.key
#openssl genrsa -out server.key 2048
2、生成服务器证书申请文件server.csr
#openssl req -new -key server.key -out server.csr -subj “/C=CN/ST=server-province/L=server-city/O=server-org/OU=server-group/CN=192.168.0.5/CN=localhost”
3、创建服务器证书配置文件cert.ext
vi cert.ext
authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = localhost
IP.2 = 192.168.0.5
4、用CA证书和CA私钥文件签署服务器证书server.crt
openssl x509 -req -in server.csr -out server.crt -days 36501 -CAcreateserial -CA myCA.crt -CAkey myCA.key -CAserial serial -extfile cert.ext
5、至此证书全部生成完成,具体证书见附件
三、在nginx服务器上安装部署
1、将server.crt 和 server.key 上传到nginx的conf目录下
2、修改nginx.conf配置文件,如下所示:
server {
listen 443 ssl;
server_name localhost;
ssl_certificate D:\\03.downloads\\nginx-1.23.3\\conf\\server.crt;
ssl_certificate_key D:\\03.downloads\\nginx-1.23.3\\conf\\server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
3、在本机启动nginx服务
四、在浏览器打开https://localhost验证效果