2015
05.01

nginx使用https自签名证书

1、制作CA证书:
ca.key CA私钥:
openssl genrsa -des3 -out ca.key 2048
制作解密后的CA私钥(一般无此必要):
openssl rsa -in ca.key -out ca_decrypted.key
ca.crt CA根证书(公钥):
openssl req -new -x509 -days 7305 -key ca.key -out ca.crt

2、制作生成网站的证书并用CA签名认证
在这里,假设网站域名为https.abc.com
生成https.abc.com证书私钥:
openssl genrsa -des3 -out https.abc.com.pem 1024
制作解密后的https.abc.com证书私钥:
openssl rsa -in https.abc.com.pem -out https.abc.com.key
生成签名请求:
openssl req -new -key https.abc.com.pem -out https.abc.com.csr
在common name中填入网站域名,如https.abc.com即可生成改站点的证书

3.用CA进行签名:
先执行以下命令
$ mkdir -p ./demoCA/newcerts
$ cd demoCA
$ echo “01” > serial
$ touch index.txt (create an empty index.txt file)
$ cd .. (so we are back in our temporary directory)

openssl ca -policy policy_anything -days 1460 -cert ca.crt -keyfile ca.key -in https.abc.com.csr -out https.abc.com.crt

4. 配置nginx
配置文件中新建一个server,并加入

listen 443;
server_name https.abc.com;
ssl on;
ssl_certificate /path/to/https.abc.com.crt;
ssl_certificate_key /path/to/https.abc.com.key;

以上2个文件路径根据实际情况配置。其他配置和http server相同。

5. 重启nginx


Hit Counter by http://yizhantech.com/