client端http协议访问nginx,为何不能反向代理为https出nginx ?

我在nginx中配置了如下虚拟主机。
我访问http://127.0.0.1:8112/,按理说应该可以反向代理到https//www.baidu.com,因为校验服务端证书的话,应该是在proxy_pass时执行。

server {
    listen 8112;
    location / {
            proxy_pass https://test8112;
    }
}
upstream test81122 {
    server www.baidu.com;

}

但是,查看error.log日志,发现如下所示的错误:
2017/04/16 21:34:14 [error] 14031#0: *1 SSL_do_handshake() failed (SSL: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol) while SSL handshaking to upstream, client: 192.168.153.1, server: saas-portal.eastdc.cn, request: "GET / HTTP/1.1", upstream: "https://14.215.177.37:80/", host: "127.0.0.1:8112"

当我用https协议访问nginx时,能正常访问https://www.baidu.com
没看过nginx源码,求大神解惑。

阅读 12.5k
1 个回答

我又去测试了,亲测可以http接入nginx,https出nginx,如下是我的测试配置,可以访问到baidu首页。

server {
    listen 8113;
    server_name saas-portal.test.cn;
    location / {
            proxy_set_header Host "www.baidu.com";
            proxy_pass https://test8113;
    }
}
upstream test8113 {
    server 115.239.211.112:443;#此ip为百度ip
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题