创建文件diploma.sh,内容如下:
#!/bin/bash
openssl genrsa -des3 -passout pass:123456 -out ssl.key 2048
mv ssl.key xxx.key
openssl rsa -in xxx.key -passin pass:123456 -out ssl.key
rm xxx.key
openssl req -new -key ssl.key -out ssl.csr -subj "/CN=RootCA/C=CN/ST=Hunan/L=ChangSha/O=MyCompanName/OU=IT"
openssl x509 -req -days 3650 -in ssl.csr -signkey ssl.key -out ssl.crt
### rename the file
NOW_DATE=`date "+%Y%m%d%H%M%S"`
if [ x$1 != x ]; then
#Have args
NEW_FILE_NAME=$1
else
#Not have args
NEW_FILE_NAME=$NOW_DATE
fi
echo $NEW_FILE_NAME
mv ssl.crt $NEW_FILE_NAME.crt
mv ssl.csr $NEW_FILE_NAME.csr
mv ssl.key $NEW_FILE_NAME.key
执行sh文件,生成相应的证书
nginx配置
ssl_certificate 指向.crt文件
ssl_certificate_key 指向.key文件