系统环境:CentOS7 64bit
nginx版本:
nginx version: nginx/1.10.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC)
built with OpenSSL 1.0.2j 26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2j --with-pcre=../pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc
目前配置了两个主机,其中host1.com用于提供API接口给安卓应用,主机配置如下:
server {
listen 443;
server_name host1.com;
ssl on;
ssl_certificate host1_cert.pem;
ssl_certificate_key host1_key.pem;
}
server {
listen 443;
server_name host2.com;
ssl on;
ssl_certificate host2_cert.pem;
ssl_certificate_key host2_key.pem;
}
使用浏览器访问,一切正常。 两个域名下的证书分别都能访问。
目前遇到的问题是,app(安卓)请求接口域名host1.com时,验证的证书却是host2.com的证书,导致请求失败,返回错误:
hostname in certificate didn't match: <host1.com> != <host2.com> OR <www.host2.com>
在命令行使用 openssl s_client -showcerts -connect host1.com:443 发现返回的是host2.com的证书。
不知道是不是nginx配置问题还是客户端请求时出问题。(初步怀疑是客户端请求的问题,因为用浏览器访问是正常的。。。)
求解。
客户端的问题。客户端需要支持 SNI 特性才能这么搞,不然一个IP+端口只能提供一张证书。不那么旧的版本的客户端都应该支持的,如果你真的要用 Android 2.x 或者 Java 6 或者 Windows XP + IE 那也是没有办法的事情,买 IP 或者多域名证书吧……
openssl s_client 后边要加 -servername xxx。