1.生成私钥文件
openssl genrsa -des3 -out server.key 2048
2.生成RSA公钥
mv server.key server.key.back
openssl rsa -in server.key.back -out server.key
3.用server.key生成证书签署请求CSR
openssl req -new -key server.key -out server.csr
4.基于生成的密钥和证书请求生成一个数字证书
openssl x509 -req -days 36500 -in server.csr -signkey server.key -out server.crt
5.把server.crt和server.key文件复制到Nginx安装目录下的 conf/ssl 位置。
6.修改nginx配置文件
代码语言:javascript复制server {
listen 443 default_server;
listen [::]:443 default_server;
server_name www.test.com;
access_log logs/test-ssl.access.log main;
ssl on;
ssl_certificate ssl/server.crt;
ssl_certificate_key ssl/server.key;
# 协议优化(可选,优化https协议,增强安全性)
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
location / {
proxy_pass http://192.168.0.136;
}
}
7.总结: