一、环境:
CentOS 6.8
nginx 1.6.0
php 7.0.10
二、背景
最近开发一个小程序,而小程序对后台接口服务器的要求是:
1、请求域名在
request合法域名
中
2、基于 https 协议
3、TLS 版本 1.2
1、2 两条都满足了,但是第三条亟待解决,导致小程序调用接口时报错:

解决微信小程序要求的TLS版本必须大于等于1.2的问题(CentOS服务器)
三、正文
(1)为什么要满足 TLS 版本 1.2 ?
2017年1月1日起,苹果强制所有 app 满足 HTTPS,即 iOS9 推出的 App Transport Security (ATS) 特性。
访问 https://www.qcloud.com/product/ssl#userDefined10 ,
输入域名,检查您的 iOS app 是否满足 ATS 特性:

解决微信小程序要求的TLS版本必须大于等于1.2的问题(CentOS服务器)
报错了,提示不支持 TLS1.2。
(2)如何满足 TLS 版本 1.2 ?
1、openSSL 版本 1.0.1
查看 openSSL 版本:
1 |
openssl version -a |
2、nginx 版本为 0.7.65,0.8.19 及更高版本
查看 nginx 版本:
1 |
nginx -V |
结果是,我的版本都符合要求。
(3)nginx 配置 TLS1.2
本人申请的是腾讯云的安全证书,官方有提供 nginx 如何配置的文档:
https://www.qcloud.com/document/product/400/6973#1.nginx-.E8.AF.81.E4.B9.A6.E9.85.8D.E7.BD.AE
配置 nginx.conf
支持 TLS1.2 的方法如下(看 ssl_protocols 参数):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<span class="hljs-section">server</span> { <span class="hljs-attribute">listen</span> <span class="hljs-number">443</span>; <span class="hljs-attribute">server_name</span> www.domain.com; <span class="hljs-comment">#填写绑定证书的域名</span> <span class="hljs-attribute">ssl</span> <span class="hljs-literal">on</span>; <span class="hljs-attribute">ssl_certificate</span> 1_www.domain.com_bundle.crt; <span class="hljs-attribute">ssl_certificate_key</span> 2_www.domain.com.key; <span class="hljs-attribute">ssl_session_timeout</span> <span class="hljs-number">5m</span>; <span class="hljs-attribute">ssl_protocols</span> TLSv1 TLSv1.<span class="hljs-number">1</span> TLSv1.<span class="hljs-number">2</span>; <span class="hljs-comment">#按照这个协议配置</span> <span class="hljs-attribute">ssl_ciphers</span> ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;<span class="hljs-comment">#按照这个套件配置</span> <span class="hljs-attribute">ssl_prefer_server_ciphers</span> <span class="hljs-literal">on</span>; <span class="hljs-attribute">location</span> / { <span class="hljs-attribute">root</span> html; <span class="hljs-comment">#站点目录</span> <span class="hljs-attribute">index</span> index.html index.htm; } } |
四、遇到的问题
按照上文一切都做完之后,发现还是不行。
折腾好久之后。
发现,原来是 nginx 之前有配另一个 https 的 server,关于
ssl_protocols 的参数值为:
1 |
ssl_protocols SSLv2 SSLv3 TLSv1; |
里面根本没有包含 TLSv1.2!从而影响了我们这个 server!
所以把改成:
1 |
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; |
此时已经完美解决Ok