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;
点击“我已充分了解可能的风险”
点击“添加例外”
点击“确认安全例外”
6、配置双向验证
nginx配置开启ssl_verify_client on;
在客户端浏览器没有安装证书的情况下访问
在客户端浏览器导入证书
将在linux服务器上生成的客户端证书下载到windows上
打开火狐浏览器的高级选项卡
在证书管理器中的您的证书中点击导入
选择证书并导入
再次刷新网页,弹出“使用确认”点击确定,就实现了双向验证
以上是nginx如何配置ssl双向验证的详细内容。更多信息请关注PHP中文网其他相关文章!