'net::ERR_INCOMPLETE_CHUNKED_ENCODING nginx

I have 2 RoR web applications hosted on 2 different servers. For one particular page, the request is served from the second application. For rest of the pages, the request is served from the main application. Nginx settings for the main application

location /customer/help/ {
            proxy_pass http://second-application:3020/help_and_support/;
}
location /assets/ {
            proxy_pass http://second-application:3020/assets/;
}

This worked fine until yesterday. Now, /customer/help/ page is not loading properly. In firefox it shows a blank page, in chrome, it loads partially and console shows an error

net::ERR_INCOMPLETE_CHUNKED_ENCODING

After debugging I found that issue might be with image data sent over API. My second app calls an API to get images and displays them on page

<% url_with_binary_data = "data:image/" + "jpeg" + ";base64," + u.photo_url.to_s %>
<%= image_tag(url_with_binary_data, :class => "userpic")  %>

API code to get the image

photo_url: Base64.encode64(u.photo.file.read).gsub("\n", '')


Solution 1:[1]

You might want to check if the user that is running the Nginx worker owns the directory /var/lib/nginx (or /var/cache/nginx in some distros).

I've learned that when you give a response too big for Nginx, it uses this directory to write as a working directory for temporary files. If the worker process cannot access it, Nginx will terminate the transmission before it completes, thus the error INCOMPLETE_CHUNKED_ENCODING.

Solution 2:[2]

Bumped into this issue on AWS and found that adding a few proxy_buffer directives to the site config file fixed the issues:

server {
    ...

    location / {
        ...
        proxy_buffers 8 1024k;  
        proxy_buffer_size 1024k;
    }
}

Solution 3:[3]

For me, the solution was what DfKimer recommended, but instead of /var/lib/nginx it was /var/cache/nginx.

Solution 4:[4]

For me the solution was enable proxy_max_temp_file_size

Solution 5:[5]

proxy_set_header Connection keep-alive;


Full config

server {
        listen      0000; #//port give by your need
        server_name  aa.com;
        proxy_buffers 16 4k;
        proxy_buffer_size 2k;


        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        location ~ ^/hello/{
            proxy_buffering off;
            proxy_pass http://127.0.0.1:1111; #//port give by your need
            proxy_redirect     off;
            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 Connection keep-alive; 
        }

Solution 6:[6]

I got this error due to server memory full. hope this helps any one in future.

Solution 7:[7]

100% Working Solution for php & nginx web server

Issue => net::ERR_INCOMPLETE_CHUNKED_ENCODING nginx

Step1 : Open /etc/php/7.2/fpm/pool.d [Select your php folder in my case i am using php 7.2]

Step2 : Edit www.conf file inside pool.d folder

In my case it's look like this =>

[inet]
user = www-data
group = www-data

listen = 127.0.0.1:9999
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 5

pm.status_path = /status
ping.path = /ping

request_terminate_timeout = 10s
request_slowlog_timeout = 10s

;
; Log files
;
access.log = /var/log/php-fpm/php-fpm.log
slowlog = /var/log/php-fpm/slow.log

Step3 : Change the value of request_terminate_timeout = 10s (Whatever time you want)

request_terminate_timeout = 300s

Step4 : Now Save and restart php-fpm (in my case i am using php7.2 so cmd will be)

sudo service php7.2-fpm restart

Now you can execute your script it will works and will terminate after 300s

Now one more thing add one more line of syntax fastcgi_read_timeout 300; inside nginx.conf file or your website .conf file [Here is code ]

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http { 
include /etc/nginx/conf-enabled/*.conf;
include /etc/nginx/sites-enabled/*.conf;    
}

After adding fastcgi_read_timeout 300; it will look like this

user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events {
    worker_connections 1024;
}

http { 
include /etc/nginx/conf-enabled/*.conf;
include /etc/nginx/sites-enabled/*.conf;
fastcgi_read_timeout 300; 
}

Now reload nginx and restart php-fpm by following cmd

sudo service php7.2-fpm reload
sudo service nginx reload

Note : The code snippet is run and tested bye me please let me know if you are not able to fix your issue via my answer

Solution 8:[8]

If proxied server cannot write to /var/lib/nginx, yo do not need to play with file permissions or ownership of that directory. You can change the cache directory of nginx for the context by;

proxy_temp_path /home/emre/projects/frontend/nginx_temp 1 2;

inside http, server or location contexts of nginx.conf file.

check http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_temp_path

Solution 9:[9]

For me the solution was to disable the cache. For context my setup is for local development and nginx is being used as reverse proxy to map domains basically

location / {
  proxy_pass http://localhost:3000;

  # don't cache it
  proxy_no_cache 1;
  # even if cached, don't try to use it
  proxy_cache_bypass 1;
}

Solution 10:[10]

This error is by nginx trying to use cache folder without right access:

  1. Make sure nginx user can write to /var/lib/nginx (or /var/cache/nginx in some distros).
  2. Make sure nginx user can write to the folder (find the nginx user form nginx configuration file is located usually in /etc/nginx/nginx.conf)
  3. Give the right access (chown -R nginx:nginx /var/lib/nginx/)
  4. Reload the service(-service nginx reload -in centos)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Ethan
Solution 3 shloosh
Solution 4 bes
Solution 5 Sheridan
Solution 6 Jomy Joseph
Solution 7 Shailesh Dwivedi
Solution 8 Emre Tapc?
Solution 9 Braulio Ruiz
Solution 10 Suraj Rao