15

We have tomcat with Jersey serving APIs behind NGINX. A new streaming API we have developed worked great when we call Tomcat directly, but started getting no response when calling it through NGINX.

Looking at NGINX logs we got:

upstream sent invalid chunked response while reading upstream

galusben
  • 5,948
  • 6
  • 33
  • 52

3 Answers3

26

We have solved the issue by adding the following to NGINX:

proxy_http_version 1.1

I guess NGINX proxies traffic by default with http version 1.0, but chunked transfer encoding is a http 1.1 feature.

https://forum.nginx.org/read.php?2,247883,247906#msg-247906

galusben
  • 5,948
  • 6
  • 33
  • 52
  • 3
    This answer already saved my life twice. I always forget what is the cause of this issue and end up here to remember. – Victor Schröder Feb 25 '21 at 16:00
  • Ha ha... I added it here due to selfish reasons, I knew I will need it in the future and will search for an answer in StackOverflow :-) – galusben Jun 24 '21 at 13:15
5

In my case, only setting proxy_http_version 1.1 did not work. I had to set these -

proxy_http_version 1.1;
proxy_set_header Connection "";
Ravi Kumar Gupta
  • 1,698
  • 2
  • 22
  • 38
0

You should add proxy_http_version 1.1,

This directive appeared in version 1.1.4.
Sets the HTTP protocol version for proxying. By default, version 1.0 is used. Version 1.1 is recommended for use with keepalive connections and NTLM authentication.

Best way, Create a http_proxy.conf file and include it in your server config:

## 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    '';
#proxy_set_header   HEADER_NAME   $VALUE;

## server.conf
server {
  listen 80;
  server_name example.domain.com
  include /etc/nginx/http_proxy.conf;    
  #.....
}

selllami
  • 182
  • 1
  • 13