我为双向 ssl 配置了一个 spring boot 服务,以使用证书验证客户端。它在 nginx 代理服务器后面。因此要求配置 nginx 以提供来自客户端的透明 https 连接并将客户端证书转发到要验证的 web 服务(后端)。还可以为不需要客户端身份验证的其他服务配置一种方式的 ssl。
类似于:
|客户| -->httpS + 客户端证书--->|NGINX|--->httpS + 客户端证书--->|服务1|
|客户| ---------->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
}
}
另外,有没有办法从证书中获取通用名称来验证客户端并在 nginx 中做出决定?因为使用 CA 是不够的。
谢谢..
最佳答案
这是不可能的。您试图做的是使 nginx 代理成为“中间人”,而 TLS 在设计上不允许这样做。
关于ssl - 配置 Nginx 将客户端证书转发到后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42252038/