nginx配置https的双向认证方式
更新时间:2024年11月19日 09:35:26 作者:CheerTan
文章主要介绍了如何配置Nginx双向认证的详细步骤,包括生成证书、配置Nginx等,并提供了个人经验供参考
GPT4.0+Midjourney绘画+国内大模型 会员永久免费使用!
【 如果你想靠AI翻身,你先需要一个靠谱的工具! 】
注意事项
配置双向认证,这里的common name需要都配置成不同
nginx 配置 https的双向认证
准备工作
linux环境安装openssl
生成证书步骤
1.新建一个文件夹
2.生成CA私钥 ca.key
3.生成ca的数字证书 ca.crt
1 2 3 4 5 6 7 8 9 | openssl req -new -x509 -days 3650 -key ca.key -out ca.crt Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: 填入组织名称等信息 |
4.生成server端的私钥
5.生成 server 端数字证书请求
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | openssl req -new -key server.key -out server.csr Country Name (2 letter code) [AU]:CN State or Province Name (full name) [Some-State]:Shanghai Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]:Sidien Test Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []:192.168.0.162 Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: 输入相关信息和密码 |
6.用 CA 私钥签发 server 的数字证书
1 | openssl x509 -req - in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 3650 |
7. 生成客户端私钥
8. 生成客户端数字请求证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | openssl req -new -key client.key -out client.csr Country Name (2 letter code) [AU]: State or Province Name (full name) [Some-State]: Locality Name (eg, city) []: Organization Name (eg, company) [Internet Widgits Pty Ltd]: Organizational Unit Name (eg, section) []: Common Name (e.g. server FQDN or YOUR name) []: Email Address []: Please enter the following 'extra' attributes to be sent with your certificate request A challenge password []: An optional company name []: 输入相关信息和密码 |
9.用CA私钥签发数字证书:client.crt
1 | openssl x509 -req - in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 3650 |
10.生成windows安装证书程序
将client.pfx拷贝到作为客户端的机器上,安装证书,输入生成时的密码
11.配置nginx
1 2 3 4 | ssl_certificate /etc/pki/ca_linvo/server/server .crt; #server公钥路径 ssl_certificate_key /etc/pki/ca_linvo/server/server .key; #server私钥路径 ssl_client_certificate /etc/pki/ca_linvo/root/ca .crt; #根级证书公钥路径,用于验证各个二级client ssl_verify_client on; 开启双向认证 |
认证成功
开启gzip跟缓存
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | gzip on; gzip_min_length 256; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_vary on; gzip_comp_level 3; gzip_disable "MSIE [1-6]\." ; gzip_proxied any; #这里设置需要压缩的格式 gzip_types application /atom +xml application /javascript application /json application /ld +json application /manifest +json application /rss +xml application /vnd .geo+json application /vnd .ms-fontobject application /x-font-ttf application /x-web-app-manifest +json application /xhtml +xml application /xml font /opentype image /bmp image /svg +xml image /x-icon text /cache-manifest text /css text /plain text /vcard text /vnd .rim.location.xloc text /vtt text /x-component text /x-cross-domain-policy ; location / { root /root/www/web ; index index.html; autoindex on; if ($request_filename ~ .*.(js|css)$) { expires 7d; } } |
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
![](http://files.jb51.net/skin/2018/images/jb51ewm.png)
微信公众号搜索 “ 脚本之家 ” ,选择关注
程序猿的那些事、送书等活动等着你
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权/违法违规/事实不符,请将相关资料发送至 reterry123@163.com 进行投诉反馈,一经查实,立即处理!
相关文章
教你利用Nginx 服务搭建子域环境提升二维地图加载性能的步骤
这篇文章主要介绍了利用 Nginx 服务搭建子域环境提升二维地图加载性能,本文分步骤通过实例代码给大家介绍的非常详细,需要的朋友参考下吧2021-09-09
最新评论