openssl genrsa -out ca.key 4096
openssl req -new -sha256 -out ca.csr -key ca.key -config ca.conf
openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt
server.conf
openssl genrsa -out server.key 2048
openssl req -new -sha256 -out server.csr -key server.key -config server.conf
openssl x509 -req -days 3650 -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt -extensions req_ext -extfile server.conf
server {
listen 443 ssl;
server_name localhost;
root D:\websocketd-0.3.0-windows_amd64;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm;
}
}
1.生成CA根证书
1.1准备ca配置文件,创建ca.conf
[ req ]
default_bits = 4096
distinguished_name = req_distinguished_name
[ req_distinguished_name ]
countryName = CN
countryName_default = CN
stateOrProvinceName = Guagdogn
stateOrProvinceName_default = Guagdogn
localityName = Guangzhou
localityName_default = Guangzhou
organizationName = AidenPC
organizationName_default = AidenPC
commonName = Aiden
commonName_max = 64
commonName_default = CA
1.2生成ca秘钥ca.key
openssl genrsa -out ca.key 4096
1.3生成ca证书签发请求ca.csr
openssl req -new -sha256 -out ca.csr -key ca.key -config ca.conf
配置文件中已经有默认值了,shell交互时一路回车就行。
1.4生成ca根证书 ca.crt
openssl x509 -req -days 3650 -in ca.csr -signkey ca.key -out ca.crt
2.生成终端用户证书
准备配置文件,得到server.conf
[ req ]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
[ req_distinguished_name ]
countryName = SAN
countryName_default = CN
stateOrProvinceName = Guangdong
stateOrProvinceName_default = Guangdong
localityName = Guangzhou
localityName_default = Guangzhou
organizationName = AidenPC
organizationName_default = AidenPC
commonName = Aiden
commonName_max = 64
commonName_default = localhost
[ req_ext ]
subjectAltName = @alt_names
[alt_names]
DNS.1 = 192.168.30.1
DNS.2 = 192.168.30.1
IP = 192.168.30.111
生成秘钥,得到server.key
openssl genrsa -out server.key 2048
生成证书签发请求,得到server.csr
openssl req -new -sha256 -out server.csr -key server.key -config server.conf
用CA证书生成终端用户证书,得到server.crt
openssl x509 -req -days 3650 -CA ca.crt -CAkey ca.key -CAcreateserial -in server.csr -out server.crt -extensions req_ext -extfile server.conf
3.Nginx配置
server {
listen 443 ssl;
server_name localhost;
root D:/Server/nginx-1.8.1;# Nginx根目录
ssl_certificate server.crt;
ssl_certificate_key server.key;
# ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# 代理1
location ~* ^/TaxHttpService/ {
proxy_pass http://localhost:9876;
}
# 代理2
location / {
proxy_pass https://10.201.36.2:8088;
}
}
把生成好的server.crt和server.key文件放在与nginx.conf同一目录下。
4.添加CA根证书
右键ca.crt安装,安装到“受信任的根证书颁发机构”(不然server.crt还是不受信任的)