生成证书链

用脚本生成一个根证书, 一个中间证书(intermediate), 三个客户端证书.

脚本来源于(有修改)
https://stackoverflow.com/que...

中间证书的域名为 localhost.


#!/bin/bash -x set -e for C in `echo root-ca intermediate`; do mkdir $C
cd $C
mkdir certs crl newcerts private
cd .. echo 1000 > $C/serial
touch $C/index.txt $C/index.txt.attr echo '
[ ca ]
default_ca = CA_default
[ CA_default ]
dir = '$C' # Where everything is kept
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.
new_certs_dir = $dir/newcerts # default place for new certs.
certificate = $dir/cacert.pem # The CA certificate
serial = $dir/serial # The current serial number
crl = $dir/crl.pem # The current CRL
private_key = $dir/private/ca.key.pem # The private key
RANDFILE = $dir/.rnd # private random number file
nameopt = default_ca
certopt = default_ca
policy = policy_match
default_days = 365
default_md = sha256 [ policy_match ]
countryName = optional
stateOrProvinceName = optional
organizationName = optional
organizationalUnitName = optional
commonName = supplied
emailAddress = optional [req]
req_extensions = v3_req
distinguished_name = req_distinguished_name [req_distinguished_name] [v3_req]
basicConstraints = CA:TRUE
' > $C/openssl.conf
done openssl genrsa -out root-ca/private/ca.key 2048
openssl req -config root-ca/openssl.conf -new -x509 -days 3650 -key root-ca/private/ca.key -sha256 -extensions v3_req -out root-ca/certs/ca.crt -subj '/CN=Root-ca' openssl genrsa -out intermediate/private/intermediate.key 2048
openssl req -config intermediate/openssl.conf -sha256 -new -key intermediate/private/intermediate.key -out intermediate/certs/intermediate.csr -subj '/CN=localhost.'
openssl ca -batch -config root-ca/openssl.conf -keyfile root-ca/private/ca.key -cert root-ca/certs/ca.crt -extensions v3_req -notext -md sha256 -in intermediate/certs/intermediate.csr -out intermediate/certs/intermediate.crt mkdir out for I in `seq 1 3` ; do
openssl req -new -keyout out/$I.key -out out/$I.request -days 365 -nodes -subj "/CN=$I.example.com" -newkey rsa:2048
openssl ca -batch -config root-ca/openssl.conf -keyfile intermediate/private/intermediate.key -cert intermediate/certs/intermediate.crt -out out/$I.crt -infiles out/$I.request
done

服务器

nginx 配置


worker_processes 1; events {
worker_connections 1024;
} stream{
upstream backend{
server 127.0.0.1:8080;
} server {
listen 8888 ssl;
proxy_pass backend;
ssl_certificate intermediate.crt;
ssl_certificate_key intermediate.key;
ssl_verify_depth 2;
ssl_client_certificate root.crt;
ssl_verify_client optional_no_ca;
}
}

客户端


curl \
-I \
-vv \
-x https://localhost:8888/ \
--proxy-cert client1.crt \
--proxy-key client1.key \
--proxy-cacert ca.crt \
https://www.baidu.com/

来源:https://segmentfault.com/a/1190000018078828

nginx 代理服务器配置双向证书验证的更多相关文章

  1. nginx配置ssl双向证书

    CA根证书制作 # 创建CA私钥 openssl genrsa -out ca.key 2048 #制作CA根证书(公钥) openssl req -new -x509 -days 3650 -key ...

  2. nginx 配置 ssl 双向证书

    CA 根证书制作 # 创建 CA 私钥 openssl genrsa -out ca.key 2048 #制作 CA 根证书(公钥) openssl req -new -x509 -days 3650 ...

  3. nginx配置https双向验证(ca机构证书+自签证书)

    nginx配置https双向验证 服务端验证(ca机构证书) 客户端验证(服务器自签证书) 本文用的阿里云签发的免费证书实验,下载nginx安装ssl,文件夹有两个文件 这两个文件用于做服务器http ...

  4. CAS (5) —— Nginx代理模式下浏览器访问CAS服务器配置详解

    CAS (5) -- Nginx代理模式下浏览器访问CAS服务器配置详解 tomcat版本: tomcat-8.0.29 jdk版本: jdk1.8.0_65 nginx版本: nginx-1.9.8 ...

  5. 使用nginx代理kibana并配置登录验证

    由于kibana不支持登录验证,谁都可以访问,放到公网就不合适了,这里配置用nginx进行代理: 生成密码文件 如果安装了httpd可以用htpasswd,比较方便: htpasswd -c /roo ...

  6. haproxy代理kibana、nginx代理kibana并实现登录验证

    在使用ELK进行日志统计的时候,由于Kibana自身并没有身份验证的功能,任何人只要知道链接地址就可以正常登录到Kibana控制界面,由于日常的查询,添加和删除日志都是在同一个web中进行,这样就有极 ...

  7. nginx 反向代理及 https 证书配置

    nginx 反向代理及 https 证书配置 author: yunqimg(ccxtcxx0) 1. 编译安装nginx 从官网下载 nginx源码, 并编译安装. ./configure --pr ...

  8. 使用nginx代理kibana并设置身份验证

    1.在es-sever上安装nginx #wget http://nginx.org/download/nginx-1.8.1.tar.gz #tar xvf nginx-1.8.1.tar.gz # ...

  9. Nginx、SSL双向认证、PHP、SOAP、Webservice、https

    本文是1:1模式,N:1模式请参见新的一篇博客<SSL双向认证(高清版)> ----------------------------------------------------- 我是 ...

随机推荐

  1. web测试点--摘录

    转载地址:Web测试到底是在测什么 一.输入框 1.字符型输入框: (1)字符型输入框:英文全角.英文半角.数字.空或者空格.特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&am ...

  2. Spring的泛型依赖注入

    Spring 4.x 中可以为子类注入子类对应的泛型类型的成员变量的引用,(这样子类和子类对应的泛型类自动建立关系)具体说明: 泛型注入:就是Bean1和Bean2注入了泛型,并且Bean1和Bean ...

  3. 2017 Multi-University Training Contest - Team 1—HDU6040

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6040 题意:不知道北航的同学为何解释题意之前都要想一段故事,导致刚开始题意不是很懂,题意就是给你n,m ...

  4. hook Extending the Framework Core

    w Task Scheduling - Laravel - The PHP Framework For Web Artisanshttps://laravel.com/docs/5.4/schedul ...

  5. FW: linux screen -recorder by ffcast convert

    fcast -s ffmpeg -r 20 -vcodec huffyuv out.avi 上面的命令会让你选择一个要录制的区域,然后呢,就会你就可以操作了,操作完后退回去按 q 键退出结束.如果你想 ...

  6. 多线程入门-第七章-线程的同步Synchronized

    /* 异步编程模型:两个线程执行自己的,互不影响. 同步编程模型:t1和t2执行,t2必须等t1执行结束之后才能执行. 为什么要线程同步? 1.为了数据的安全,尽管应用程序的使用率降低,但是为了保证数 ...

  7. Python3量化技术常用插件

    1. 确定自己的系统为64位版本 2. 下载安装Python3 64位版本 如果要使用zipline,建议使用python3.5.另外发现很多东西要求的也是3.5. 主页地址: https://www ...

  8. HDFS基本工作机制

  9. HDFS集群安装

    DFS集群安装: 1.准备工作 (1)虚拟机(电脑8G 磁盘500GB) (2)3台linux系统(1台namenode 2台datanode) 2.安装HDFS(软件) (1)关闭防火墙 firew ...

  10. python常见模块之random模块

    import random print(random.random()) #随机产生一个0-1之间的小数 print(random.randint(1,3)) #随机产生一个1-3之间的整数,包括1和 ...