将 Nginx 从 1.18 升级到 1.24 后,我们收到以下错误:
upstream sent duplicate header line: "Transfer-Encoding: chunked", previous value: "Transfer-Encoding: chunked" while reading response header from upstream, client: 54.xx.xx.xx, server: backend.example.com, request: "POST /test/file HTTP/1.1", upstream: "http://10.0.xx.xx:6067/test/file", host: "backend.example.com", referrer: "https://app.example.com/
Nginx 版本: nginx/1.24.0
操作系统版本:Ubuntu 22.04.3 LTS
配置:
后端.conf
server {
access_log /var/log/nginx/access.log;
index index.html index.htm index.nginx-debian.html;
server_name backend.example.com;
include /etc/nginx/http_proxy.conf;
location /test/file {
proxy_pass http://10.0.xx.xx:6067/test/file;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host $host:443;
}
listen 443 ssl;
ssl_certificate /etc/backend.example.com/fullchain.pem;
ssl_certificate_key /etc/backend.example.com/privkey.pem;
include /etc/options-ssl-nginx.conf;
ssl_dhparam /etc/ssl-dhparams.pem;
}
http_proxy.conf
proxy_buffers 32 4k;
proxy_http_version 1.1;
proxy_send_timeout 60;
proxy_read_timeout 60;
proxy_connect_timeout 60;
proxy_set_header Connection '';
请求已在后端(spring-boot)成功处理,但我们在后端 Nginx 的 error.log 中收到上述错误,这使得前端失败并显示 502
如果我们从服务器块中删除 include /etc/nginx/http_proxy.conf; 我们收到以下错误:
upstream sent invalid chunked response while reading upstream, client: 54.xx.xx.xx,server: backend.example.com, request: "POST /test/file HTTP/1.1”, upstream: "http://10.0.xx.xx:6067/test/file", host: "backend.example.com”, referrer: "https://app.example.com/
如果需要其他详细信息,请告诉我。
感谢任何解决此问题的帮助或指导。 预先感谢。
几天前,我将 Nginx 从 1.18.0 升级到 1.24.0 后遇到了同样的错误。我尝试了太多参数。
您应该尝试在 nginx.conf 中添加此“chunked_transfer_encoding off”参数。这解决了我的问题。
sendfile on;
server_tokens off;
keepalive_timeout 65;
chunked_transfer_encoding off;
include /etc/nginx/conf.d/*.conf;
要解决很多人升级Nginx后遇到的错误,可以直接在Nginx目录(/etc/nginx/nginx.conf)下的配置文件(nginx.conf)中添加“chunked_transfer_encoding off;”参数。