配置 Nginx 将客户端证书转发到后端

BaS*_*Sic 5 ssl https certificate nginx x509

我为两种方式的 ssl 配置了一个 Spring Boot 服务,以使用证书验证客户端。它在 nginx 代理服务器后面。所以需求是配置nginx提供来自客户端的透明https连接,并将客户端证书转发到webservice(backend)进行验证。还为不需要客户端身份验证的其他服务配置一种方式 ssl。

就像是:

  1. |客户| -->httpS + 客户端证书--->|NGINX|--->httpS + 客户端证书--->|服务1|

  2. |客户| ------------>httpS----------->|NGINX| ------------>http------------>|服务 2|

我的 nginx 配置:

server {
    listen       443;
    server_name  xx.xx.xx.xxx;

     ssl on;
     ssl_certificate      /path/to/server/cert.crt;
     ssl_certificate_key  /path/to/server/key.key;
     ssl_client_certificate /path/to/ca.crt;
     ssl_verify_client optional;

     location /service1/ {
         proxy_pass https://service1:80/;   
         #Config to forward client certificate or to forward ssl connection(handshake) to service1
     }

     location /service2/ {
         proxy_pass http://service2:80/;
         #http connection
     }
}
Run Code Online (Sandbox Code Playgroud)

另外,有没有办法从证书中获取通用名称来验证客户端并在 nginx 中做出决定?因为使用 CA 是不够的。

谢谢..

小智 4

这不可能。您尝试做的是将 nginx 代理设置为“中间人”,而 TLS 的设计不允许这样做。