Nginx代理到SSL客户端证书authentication的后端

我有两台服务器,都有nginx。 服务器A正在侦听443,并configuration为使用客户端SSL证书进行身份validation。

服务器B有一个内部进程需要通过nginx与服务器A进行通信。

我想在服务器B上configurationNginx,它将侦听8080(不encryption,因为它是全部本地通信),并且proxy_pass到ServerA:443。

问题是如何注入客户证书? 我没有find任何proxy_xxxx函数。

我知道如何使用与socat相当的,但我的要求是使用nginx。

客户端证书详细信息是否足以通过?

你可以加

 proxy_set_header X-SSL-CERT $ssl_client_cert; 

到您的configuration,然后证书信息通过X-SSL-Cert标头可用于服务器B.

显然,这是你正在寻找的: http : //nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ssl_certificate从1.7.8版本可用。

 location / { ... proxy_pass the_other_nginx; proxy_ssl_certificate the_certificate.pem; ... } 

这个问题似乎主要是版本依赖。 在Ubuntu 14.04 LTS上,默认的nginx是一个过时的1.4。 首先,您需要安装基于PPA的版本

https://leftshift.io/upgrading-nginx-to-the-latest-version-on-ubuntu-servers

演示如何使用以下操作:

 sudo add-apt-repository ppa:nginx/stable sudo aptitude safe-upgrade 

你最终应该:

 nginx -v nginx version: nginx/1.8.0 

来自@ xatr0z的configurationhttps://serverfault.com/a/636455/162693指向http://www.senginx.org/en/index.php/Proxy_HTTPS_Client_Certificate不起作用:

非工作提案

 backend { server some-ip:443; } server { listen 80; location / { proxy_ssl_certificate certs/client.crt; proxy_ssl_certificate_key certs/client.key; proxy_pass https://backend; } } 

与1.8.0不能开箱即用。 这可能只是一个提示而已,不能用作configuration文件,或者依赖于另一个版本。

我正在使用基于apache2的后端服务器A进行testing,并启用了SSL和自签名客户端证书。 ApacheconfigurationSSLOptions设置为:

 SSLOptions +ExportCertData +FakeBasicAuth + StdEnvVars 

由于后端的phpinfo()脚本将显示服务器端和客户端信息,这使得debugging情况更加容易。

validation这个我用:

HTTPS://后端/testing/的phpinfo

在浏览器中安装了SSL证书,我得到如下部分:SSL_SERVER_S_DN_CN用于服务器证书,SSL_CLIENT_S_DN_CN用于客户端证书。

作为我使用的第一个开始(填写括号中的部分)在前端服务器B上configurationnginx:

 server { listen 8080; server_name <frontend>; location / { proxy_buffering off; proxy_pass https://<backend>; #proxy_ssl_certificate certs/<SSL Client Certificate>.crt; #proxy_ssl_certificate_key certs/<SSL Client Certificate>.key; } } 

解开SSL客户端证书的特定部分来检查反向代理本身是否工作。

 nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful service nginx restart nginx stop/waiting nginx start/running, process 8931 

现在http:// frontend:8080 / test / phpinfo.php的作品

显示服务器证书的SSL_SERVER_S_DN_CN,并且尚未显示客户端证书的SSL_CLIENT_S_DN_CN

现在取消注释后:

 server { listen 8080; server_name <frontend>; location / { proxy_buffering off; proxy_pass https://<backend>; proxy_ssl_certificate certs/<SSL Client Certificate>.crt; proxy_ssl_certificate_key certs/<SSL Client Certificate>.key; } } 

并检查/重新启动

 nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful service nginx restart nginx stop/waiting nginx start/running, process 8931 

http:// frontend:8080 / test / phpinfo.php的作品和

显示服务器证书的SSL_SERVER_S_DN_CN 并显示客户端证书的SSL_CLIENT_S_DN_CN

所以现在我们按照要求开展工作了。

请注意错误https://trac.nginx.org/nginx/ticket/872#ticket

关于nginx和SSL客户端证书的文章还挺多, 它使用PHP与FastCGI作为例子,但我认为你可以适应,反向代理设置:

 server { listen 443; ssl on; server_name example.com; ssl_certificate /etc/nginx/certs/server.crt; ssl_certificate_key /etc/nginx/certs/server.key; ssl_client_certificate /etc/nginx/certs/ca.crt; ssl_verify_client optional; location / { root /var/www/example.com/html; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME /var/www/example.com/lib/Request.class.php; fastcgi_param VERIFIED $ssl_client_verify; fastcgi_param DN $ssl_client_s_dn; include fastcgi_params; } } 

来源http://nategood.com/client-side-certificate-authentication-in-ngi

看来这个SEnginx模块是你正在寻找的: http : //www.senginx.org/en/index.php/Proxy_HTTPS_Client_Certificate