方法1:生成自签名证书(既是服务端证书又充当CA根证书)
#!/bin/sh# Generate self-signed server certificate:read -p "Enter your domain or server name or ip: " DOMAINecho "Generate server.key..."openssl genrsa -des3 -out server.key 2048echo "Generate server certificate signing request..."SUBJECT="/C=CN/ST=JS/L=NJ/O=MY/OU=MY/CN=$DOMAIN"openssl req -new -subj $SUBJECT -key server.key -out server.csrecho "Remove server.key password..."mv server.key server.origin.keyopenssl rsa -in server.origin.key -out server.keyecho "Sign SSL certificate..."openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crtecho "---- SSL certificate generate OK!!!! ----"echo "TODO:"echo "Add configuration in nginx:"echo "server {"echo " ..."echo " listen 443 ssl;"echo " ssl_certificate /yourpath/server.crt;"echo " ssl_certificate_key /yourpath/server.key;"echo "}"
注意:在脚本执行过程中会要求输入多次的密码,请确保这些密码是一样的。
方法2:生成独立的CA证书和Server证书:
未完待续