个人技术空间

创建自签名HTTPS证书

首先创建CA证书

openssl genrsa  -out CA.key
openssl req -x509 -new -nodes -key CA.key -sha256 -days 1825 -out CA.pem \
-subj "/CN=Alien/emailAddress=alien@aliencn.net"

创建一个HTTPS证书

#指定域名
domain="ssl.aliencn.net"
#生成一个证书
openssl genrsa -out $domain.key
#创建域名申请
openssl req -new -key $domain.key -out $domain.csr \
-subj "/CN=Alien/emailAddress=alien@aliencn.net"

#使用CA签发此证书
#生成配置
echo "authorityKeyIdentifier=keyid,issuer
basicConstraints=CA:FALSE
keyUsage = digitalSignature, nonRepudiation, keyEncipherment, dataEncipherment
subjectAltName = @alt_names
[alt_names]
DNS.1 = $domain" >ext.conf
#签发此证书
openssl x509 -req -in $domain.csr -CA CA.pem -CAkey CA.key -CAcreateserial \
-out $domain.crt -days 1825 -sha256 -extfile ext.conf

签发完成后,会生成ssl.aliencn.net.crt和ssl.aliencn.net.key两个证书文件。
可以直接配置在Nginx上。

然后,将CA.pem根证书导入到客户端的受信任的根证书颁发机构中。

配置完成后,打开浏览器使用https访问域名,就可以了。

版权声明:署名-非商业性使用-禁止演绎 3.0 未本地化版本 (CC BY-NC-ND 3.0)