28

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", '')

12 Answers 12

52

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.

12
  • I am getting same error. If issue related to nginx then how we can fix it?
    – kd12
    Dec 1, 2015 at 6:10
  • If you navigate to /var/lib/nginx and run ls -lah, what's the output?
    – DfKimera
    Dec 2, 2015 at 13:48
  • 2
    You never knew how this saved me! Jul 4, 2016 at 7:27
  • 3
    Check which user nginx is running (generally in nginx.conf), then you'll want to give ownership of the nginx lib directory to that user chown -R nginx:nginx /var/lib/nginx/. You can reload nginx (service nginx reload on CentOS 6) just in case.
    – Don Wilson
    Sep 14, 2016 at 19:51
  • This solved my problem too, while proxying Kibana 5.4 via nginx.
    – Ajay M
    Nov 4, 2017 at 14:10
28

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;
    }
}
1
  • 3
    This fixed my problem. Any idea why this helps?
    – adotout
    Sep 11, 2019 at 22:19
6

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

1
  • I am on mac v12.4 and installed via homebrew and it was /opt/homebrew/var/run/nginx Jun 30, 2022 at 2:26
1

For me the solution was enable proxy_max_temp_file_size

1

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; 
        }
1

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

1
  • Same for me on my Kibana server, a 'df -h' shows that the server was full, nginx was unable to cache new files in /var/cache/nginx, preventing Kibana to load (Kibana did not load properly). Making some space resolved the issue. Oct 6, 2020 at 6:55
1

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

0

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

0

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;
}
0

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)
0

To add another solution to this thread. I was getting the error (failed)net::ERR_INCOMPLETE_CHUNKED_ENCODING from Nginx after using SSE but it was working fine if I called the server directly. The reason was that Nginx was having a read timeout for 60 seconds. It can be overridden by using the proxy_read_timeout directive like the following to make it for 24 hours as an example:

proxy_read_timeout 24h;
0

The main cause of the issues was due to timedout issues. So the solution which works for me was to increase the value of the following nginx block as per your need in seconds.

http {
  ...
  send_timeout 200; # 200 seconds
  ...
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.