创建证书
1. 创建KEY
DOMAIN=www.test.com
openssl genrsa -des3 -out $DOMAIN.key 1024
2. 创建证书请求
SUBJECT="/C=US/ST=HuBei/L=WuHan/O=www/OU=web/CN=$DOMAIN"
openssl req -new -subj $SUBJECT -key $DOMAIN.key -out $DOMAIN.csr
3. 清除KEY密码
mv $DOMAIN.key $DOMAIN.origin.key
openssl rsa -in $DOMAIN.origin.key -out $DOMAIN.key
4. 签署证书
openssl x509 -req -days 3650 -in $DOMAIN.csr -signkey $DOMAIN.key -out $DOMAIN.crt
Nginx配置SSL
server {
....
listen 443 ssl;
ssl_certificate /etc/nginx/ssl/$DOMAIN.crt;
ssl_certificate_key /etc/nginx/ssl/$DOMAIN.key;
}
使用脚本生成
bash -c "$(curl https://gitee.com/yx571304/my_oschina/raw/master/nginx/gencert.sh)"