为nginx代理服务器强制使用特定的SSL协议

我正在开发一个远程https Web服务的应用程序。 在开发时,我需要从本地开发服务器(在ubuntu上运行nginx)到远程https web服务器的代理请求。 这里是相关的nginxconfiguration:

server { server_name project.dev; listen 443; ssl on; ssl_certificate /etc/nginx/ssl/server.crt; ssl_certificate_key /etc/nginx/ssl/server.key; location / { proxy_pass https://remote.server.com; proxy_set_header Host remote.server.com; proxy_redirect off; } } 

问题是远程HTTPS服务器只能接受通过SSLv3的连接,如下面的openssl调用所示。

不工作:

 $ openssl s_client -connect remote.server.com:443 CONNECTED(00000003) 139849073899168:error:140790E5:SSL routines:SSL23_WRITE:ssl handshake failure:s23_lib.c:177: --- no peer certificate available --- No client certificate CA names sent --- SSL handshake has read 0 bytes and written 226 bytes --- New, (NONE), Cipher is (NONE) Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE --- 

加工:

 $ openssl s_client -connect remote.server.com:443 -ssl3 CONNECTED(00000003) <snip> --- SSL handshake has read 1562 bytes and written 359 bytes --- New, TLSv1/SSLv3, Cipher is RC4-SHA Server public key is 1024 bit Secure Renegotiation IS NOT supported Compression: NONE Expansion: NONE SSL-Session: Protocol : SSLv3 Cipher : RC4-SHA <snip> 

使用当前设置,当我在浏览器中连接到它时,我的nginx代理会提供一个502 Bad Gateway 。 在错误日志中启用debug我可以看到消息: [info] 1451#0: *16 peer closed connection in SSL handshake while SSL handshaking to upstream

我尝试添加ssl_protocols SSLv3; 到nginxconfiguration,但没有帮助。

有谁知道我可以设置这个正常工作?

编辑 – 添加了所需的其他信息:

在OpenSSL版本的Ubuntu 12.04上运行:

 $ openssl version OpenSSL 1.0.1 14 Mar 2012 

解决scheme

下面@Christopher Perrin提供的解决scheme是将openssl降级到1.0.0。 以下是为我成功完成的命令(在AMD64上运行的Ubuntu 12.04):

 wget http://launchpadlibrarian.net/81976289/openssl_1.0.0e-2ubuntu4_amd64.deb sudo dpkg -i openssl_1.0.0e-2ubuntu4_amd64.deb wget http://launchpadlibrarian.net/81976290/libssl1.0.0_1.0.0e-2ubuntu4_amd64.deb sudo dpkg -i libssl1.0.0_1.0.0e-2ubuntu4_amd64.deb 

这里解释你的问题的可能的解决scheme

由于错误,您必须在Nginx系统中降级到OpenSSL 1.0.0。

这是因为当你尝试Nginx编译Openssl 1.0.1版本时,他们已经介绍了TLSv1.1和TLSv1.2,只要Nginx试图连接到后端服务器,它将重置连接与peer closed connection in SSL handshake (54: Connection reset by peer) while SSL handshaking to upstream Nginxdebugging日志中的peer closed connection in SSL handshake (54: Connection reset by peer) while SSL handshaking to upstream这意味着后端没有TLSv1.1和TLSv1.2的支持。

如果正在使用Load Balancer,则您/客户端需要升级其Load Balancer Frimware。

尝试强制服务器宣布的SSL版本

 ssl_prefer_server_ciphers on; ssl_protocols SSLv3 TLSv1; # Set the ciphers to use. You may have to fix formatting. ssl_ciphers DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:\ EDH-RSA-DES-CBC3-SHA:AES256-SHA:DES-CBC3-SHA:\ AES128-SHA:RC4-SHA:RC4-MD5; 

在最近一次升级Nginx盒子上的openssl库之后,我遇到了一个类似的问题,在Windows 2003上反向代理Nginx到IIS 6。 对我来说,工作是改变Nginx指令:

 ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 

 proxy_ssl_protocols TLSv1;