net::ERR_INCOMPLETE_CHUNKED_ENCODING nginx

2019-02-09 01:10发布

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

4条回答
太酷不给撩
2楼-- · 2019-02-09 01:25

You might want to check if the user that is running the Nginx worker owns the directory /var/lib/nginx.

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.

查看更多
一夜七次
3楼-- · 2019-02-09 01:31

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;
    }
}
查看更多
不美不萌又怎样
4楼-- · 2019-02-09 01:39

For me the solution was enable proxy_max_temp_file_size

查看更多
5楼-- · 2019-02-09 01:42

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

查看更多
登录 后发表回答