nginx报错upstream sent invalid chunked response while reading upstream

当A项目通过HttpURLConnection被Nginx负载均衡代理时,出现ERR_EMPTY_RESPONSE错误。原因是HTTP协议版本不一致。解决方法是在Nginx配置中添加`proxy_http_version1.1`和相关设置。

缘由:A项目用HttpURLConnection代理(B项目)内部接口的时候,返回值正常;
由于要走负载,nginx代理了几个A项目,通过nginx访问的时候,页面显示ERR_EMPTY_RESPONSE;
nginx报错upstream sent invalid chunked response while reading upstream.

原因
http协议版本不一致导致

解决方案
在nginx.conf的location里加上

proxy_http_version 1.1;
proxy_set_header   Connection       ""; //重要
举个例子

location /redirect/ {
    proxy_pass http://localhost:8080/;
    proxy_http_version 1.1;
    proxy_set_header   Connection       "";
    proxy_set_header   Host             $host;
    proxy_set_header   X-Real-IP        $remote_addr;
    proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_cookie_path / /redirect;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值