nginx报错upstream sent invalid chunked response while reading upstream

缘由: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;
}

完毕!

你可能感兴趣的:(nginx,java,linux,mysql,bug)