---
title: "iOS9下基于ATS对HTTPS要求的  tls 1.2环境之nginx环境配置"
author: "lunzi"
date: "2016-12-15T16:48:45Z"
tags: ["CentOS", "HTTPS", "PHP", "Security", "nginx"]
categories: ["移动开发"]
slug: "ios9-ats-https-tls-1-2-nginx"
draft: false
lastmod: "2016-12-15T16:49:54Z"
id: 2345083
url: "https://lunzi.iteye.com/blog/2345083"
---

一、需求 
iOS9中新增App Transport Security（简称ATS）特性, 主要使到原来请求的时候用到的HTTP，都转向TLS1.2协议进行传输。这也意味着所有的HTTP协议都强制使用了HTTPS协议进行传输。因此移动api需要配置为https并且要支持tls 1.2

二、项目情况
服务器端：公司的服务器的采用的操作系统是centos，开发语言php，web容器采用的nginx。
客户端：ios android
客户端和服务的通信采用http和json
app内的部分功能通过webbiew加载h5完成。

三、最终配置成功
nginx.conf中的相关配置如下：

```java
server
        {
                server_name mobileapi.xx.com;
                index index.html index.htm index.php default.html default.htm default.php;
                root  /home/wwwroot/mobileapi.xx.com/web;


                listen 443 ssl;
                 ssl on;
                 ssl_certificate        /home/wwwroot/ssl.xx.com/xx.crt;
                 ssl_certificate_key    /home/wwwroot/ssl.xx.com/xx.key;
                 ssl_session_timeout  5m;
                
                ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
                ssl_ciphers AESGCM:ALL:!DH:!EXPORT:!RC4:+HIGH:!MEDIUM:!LOW:!aNULL:!eNULL;
                ssl_prefer_server_ciphers   on;



                include none.conf;
                location ~ .*\.(php|php5)?$
                        {
                                try_files $uri =404;
                                #fastcgi_pass  unix:/tmp/php-cgi.sock;
                                fastcgi_pass  unix:/dev/shm/php-cgi.sock;
                                fastcgi_index index.php;
                                include fcgi.conf;
                        }

                location /{
                                 if (!-e $request_filename){
                                          rewrite ^/(.*) /index.php last;
                                  }
                }
                location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
                        {
                                expires      30d;
                        }

                location ~ .*\.(js|css)?$
                        {
                                expires      12h;
                        }

                access_log off;
        }

```


四、关键软件的版本
nginx 1.11.7 
openssl 1.0.1e-fips
contos 6.3

五、nginx和openssl安装
openssl安装yum install openssl
从官网下载nginx 1.11.7
nginx安装命令：./configure  --prefix=/usr/local/nginx1_11_7   --with-http_ssl_module 


六、测试方法
nscurl --ats-diagnostics https://mobileapi.xx.com
如果全部pass 证明配置成功

七、遇到的坑
nginx当时是1.4.4版本太低，不支持tls 1.2
openssl版本太低，当时是0.9.8e
CentOS 如果是5.x的，升级openssl要手工，没法用yum


七、参考资料

https://my.oschina.net/vimfung/blog/494687
https://zhidao.baidu.com/question/1114939951869020059.html
http://blog.sina.com.cn/s/blog_4e11d20b0102vmne.html
http://bguncle.blog.51cto.com/3184079/1392870/
http://www.cnblogs.com/hitwtx/archive/2012/02/13/2349742.html
https://my.oschina.net/u/1423896/blog/267511