http://blog.csdn.net/lvye1221/article/details/53843607
缘由
当前公司服务器已经采用 http 协议的方式部署成功,可 App Store 要求必须采用 https 协议,那么,能否在不改变公司服务器代码的情况下,实现 https 的要求呢?
答案是肯定的,采用 Nginx 反向代理实现(以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器)。
windows 环境下安装
一些代码
- 1
- 2
- 3
- 4
- 5
启动
- 1
- 2
- 3
- 4
- 5
- 6
停止
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
重新载入
- 1
配置
nginx-1.10.2/conf/nginx.conf
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
配置好后,打开地址即可访问页面( html/data/up1 下的默认首页)
启动 ssl
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
可以打开这个地址
https://localhost:8080
当然,浏览器会提示站点不安全,解决这个问题的方式是 选择官方颁布的 SSL 证书
反向代理
方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端
示例
将 1.gif 放在 html/data/up1 目录下
详细可参照帮助文档
http://nginx.org/en/docs/beginners_guide.html
服务器1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
服务器2
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
http://localhost:82/1.gif
如果最后配置打开后,相当于找 root 为 html/data/images/1.gif 的文件
http://localhost:82/images/1.gif ==> http://localhost:82/data/images/1.gif
因为匹配到了 /images/ 相当于找 root 为 html/data/images/1.gif
http://localhost:82/data/images/1.gif ==> http://localhost:8080/data/images/data/images/1.gif
所以,找不到了
https 转 http
转发测试示例
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
苹果ATS验证
更新Nginx根目录下 conf/nginx.conf 文件如下:
server {
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
}
允许windows 防火墙端口例外
443
nginx 配置
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
技巧
发现错误的调试方法
查看错误日志,这里通常会写好路径转发的测试
c:/nginx-1.10.2/logs/error.log
IP地址的SSL可以访问,但域名不可以
找了好久,才发现测试的 域名 与 IP 地址不一致,当然域名访问不了啦
参考资料
反向代理:Web服务器的“经纪人”
http://www.open-open.com/lib/view/open1417488526633.html
修改转发的信息
http://blog.csdn.net/u010391029/article/details/50395680
SSL证书配置
http://www.wosign.com/news/ios-app-https.htm