原文参考链接:https://www.cnblogs.com/leilcoding/p/16138778.html
编写生成证书的脚本
vim gen-ssl.sh
powershell
#!/bin/sh
# create self-signed server certificate:
read -p "Enter your domain [www.example.com]: " DOMAIN
echo "Create server key..."
openssl genrsa -des3 -out $DOMAIN.key 2048
echo "Create server certificate signing request..."
SUBJECT="/C=US/ST=Mars/L=iTranswarp/O=iTranswarp/OU=iTranswarp/CN=$DOMAIN"
openssl req -new -subj $SUBJECT -key $DOMAIN.key -out $DOMAIN.csr
echo "Remove password..."
mv $DOMAIN.key $DOMAIN.origin.key
openssl rsa -in $DOMAIN.origin.key -out $DOMAIN.key
echo "Sign SSL certificate..."
openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt
执行脚本
chmod a+x gen-ssl.sh
./gen-ssl.sh
拷贝证书到nginx中
cp ./<域名>.crt /etc/nginx/ssl/
cp ./<域名>.key /etc/nginx/ssl/
编辑nginx(不同版本不一样)
xml
#新版本
listen 80 ssh;
ssl_certificate /etc/nginx/ssl/<域名>.crt;
ssl_certificate_key /etc/nginx/ssl/<域名>.key;
#老版本
listen 86;
ssl on;
ssl_certificate /etc/nginx/ssl/<域名>.crt;
ssl_certificate_key /etc/nginx/ssl/<域名>.key;