openssl genrsa -out key.pem 2048
openssl req -new -key key.pem -out cert.csr
會提示輸入省份、城市、域名信息等,重要的是,email 必定要是你的域名後綴的你能夠拿着這個文件去數字證書頒發機構(即CA)申請一個數字證書。CA會給你一個新的文件cacert.pem,那纔是你的數字證書。html
若是是本身作測試,就能夠用下面這個命令來生成證書:node
openssl req -new -x509 -nodes -out server.crt -keyout server.key
#雙向認證nginx
openssl genrsa -des3 -out ca.tmp.key 4096
openssl rsa -in ca.tmp.key -out ca.key openssl req -new -x509 -days 365 -key ca.key -out ca.crt
openssl x509 -in ca.crt -out ca.der -outform DER
openssl genrsa -des3 -out server.tmp.key 1024
openssl rsa -in server.tmp.key -out server.key
這一步須要幾項目內容,關鍵點Common Name不能與CA證書的Common Name相同,不然在進行 openssl verify的時候會出現error 18 at 0 depth lookup:self signed certificate服務器
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt
openssl genrsa -des3 -out client.key 1024
這步會提示輸入幾詳細內容,重要的內容是Common Name必須與服務器端證書的Common Name一致session
openssl req -new -key client.key -out client.csr
openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt
openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
openssl pkcs12 -export -in client.crt -inkey client.key -out client.pfx
##==================驗證證書=====================測試
openssl verify -purpose sslserver -CAfile ca.crt client.crt
openssl verify -purpose sslserver -CAfile ca.crt server.crt
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module make make install
server { listen 443 ssl; server_name localhost,fd.chinasws.com; #ssl_certificate cert.pem; #ssl_certificate_key cert.key; # start ssl_certificate ssl/ca2/server.crt; ssl_certificate_key ssl/ca2/server.key; ssl_client_certificate ssl/ca2/ca.crt; ssl_verify_client on; # end #ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; #allow 10.0.26.41; # deny all; }