|
Nginx 请求头冲突报错 upstream sent "Content-Length" and "Transfer-Encoding" headers at the same ...
upstream sent "Content-Length" and "Transfer-Encoding" headers at the same time 错误,是一个典型的 HTTP 协议合规性问题。根据 HTTP 标准(RFC 7230),同一个响应中不能同时存在 Content-Length 和 Transfer-Encoding: chunked 头。现时场景是上游服务带的这两个头,请求时,Nginx直接报502错误。
处理方法
确保你的 Nginx 代理配置指向的上游服务器(upstream)使用了 proxy_http_version 1.1
修改location配置如下:
location / {
proxy_pass http://192.*.*.102:9090/auth/route;
# 确保你的 Nginx 代理配置指向的上游服务器(upstream)使用了 proxy_http_version 1.1
proxy_http_version 1.1;
# 使用more_clear_headers直接清除Transfer-Encoding头(需要重新编译nginx,添加模块headers-more-nginx-module,不过测试过,这行配置貌似并没有作用)
more_clear_headers 'Transfer-Encoding';
# 基础配置
proxy_buffering on;
proxy_buffer_size 16k;
proxy_buffers 4 16k;
chunked_transfer_encoding off;
}
|