nginx如何配置ssl雙向驗證

1、安裝nginx

2、使用openssl實現證書中心
由于是使用openssl架設私有證書中心,因此要保證以下字段在證書中心的證書、服務端證書、客戶端證書中都相同
country name
state or province name
locality name
organization name
organizational unit name

編輯證書中心配置文件
vim /etc/pki/tls/openssl.cnf

[ ca_default ]
dir ? ? ? ? ? ? = /etc/pki/ca
certs ? ? ? ? ? = $dir/certs ? ? ? ? ? ?# where the issued certs are kept
crl_dir ? ? ? ? = $dir/crl ? ? ? ? ? ? ?# where the issued crl are kept
database ? ? ? ?= $dir/index.txt ? ? ? ?# database index file.
#unique_subject = no ? ? ? ? ? ? ? ? ? ?# set to ‘no’ to allow creation of
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# several ctificates with same subject.
new_certs_dir ? = $dir/newcerts ? ? ? ? # default place for new certs.
certificate ? ? = $dir/cacert.pem ? ? ? # the ca certificate
serial ? ? ? ? ?= $dir/serial ? ? ? ? ? # the current serial number
crlnumber ? ? ? = $dir/crlnumber ? ? ? ?# the current crl number ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?# must be commented out to leave a v1 crl
crl ? ? ? ? ? ? = $dir/crl.pem ? ? ? ? ?# the current crl
private_key ? ? = $dir/private/cakey.pem# the private key
randfile ? ? ? ?= $dir/private/.rand ? ?# private random number file

[ req_distinguished_name ]
countryname ? ? ? ? ? ? ? ? ? ? = country name(2 letter code)
countryname_default ? ? ? ? ? ? = cn
countryname_min ? ? ? ? ? ? ? ? = 2
countryname_max ? ? ? ? ? ? ? ? = 2
stateorprovincename ? ? ? ? ? ? = state or province name (full name)
stateorprovincename_default ? ? = fj
localityname ? ? ? ? ? ? ? ? ? ?= locality name (eg, city)
localityname_default ? ? ? ? ? ?= fz
0.organizationname ? ? ? ? ? ? ?= organization name (eg, company)
0.organizationname_default ? ? ?= zdz
organizationalunitname ? ? ? ? ?= organizational unit name (eg, section)
organizationalunitname_default ?= zdz

創建證書私鑰
cd /etc/pki/ca/private
(umask 077;openssl genrsa -out?cakey.pem 2048)
生成自簽證書
cd /etc/pki/ca/
openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days=3655

3、創建服務器證書
mkdir /usr/local/nginx/ssl
cd /usr/local/nginx/ssl
(umask 077;openssl genrsa -out nginx.key 1024)
openssl req -new -key nginx.key -out nginx.csr
openssl ca -in nginx.csr -out nginx.crt -days=3650

4、創建客戶端瀏覽器證書
(umask 077;openssl genrsa -out client.key 1024)
openssl req -new -key client.key -out client.csr
openssl ca -in client.csr -out client.crt -days=3650
將文本格式的證書轉換成可以導入瀏覽器的證書
openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12 ?

5、配置nginx服務器驗證
vim /usr/local/nginx/conf/nginx.conf
ssl on;
ssl_certificate ? ? ? ? /usr/local/nginx/ssl/nginx.crt;
ssl_certificate_key ? ? /usr/local/nginx/ssl/nginx.key;
ssl_client_certificate ?/usr/local/nginx/ssl/cacert.pem;
ssl_session_timeout ? ? 5m;
#ssl_verify_client ? ? ? on; ? ? ? ? ? ? ? ? ? ? ? ? 服務器驗證客戶端,暫時不開啟,讓沒有證書的客戶端可以訪問,先完成單向驗證
ssl_protocols ? ? ? ? ? sslv2 sslv3 tlsv1;
nginx如何配置ssl雙向驗證
點擊“我已充分了解可能的風險”
nginx如何配置ssl雙向驗證
點擊“添加例外”
nginx如何配置ssl雙向驗證
點擊“確認安全例外”
nginx如何配置ssl雙向驗證

6、配置雙向驗證
nginx配置開啟ssl_verify_client ? ? ? on; ? ?
在客戶端瀏覽器沒有安裝證書的情況下訪問

nginx如何配置ssl雙向驗證
在客戶端瀏覽器導入證書
nginx如何配置ssl雙向驗證
將在linux服務器上生成的客戶端證書下載到windows上
nginx如何配置ssl雙向驗證
打開火狐瀏覽器的高級選項卡
nginx如何配置ssl雙向驗證
在證書管理器中的您的證書中點擊導入
nginx如何配置ssl雙向驗證
選擇證書并導入
nginx如何配置ssl雙向驗證
再次刷新網頁,彈出“使用確認”點擊確定,就實現了雙向驗證

? 版權聲明
THE END
喜歡就支持一下吧
點贊11 分享