weserv / images

Source code of wsrv.nl (formerly images.weserv.nl), to be used on your own server(s).
https://wsrv.nl/
BSD 3-Clause "New" or "Revised" License
1.84k stars 188 forks source link

Docker Alpine: ERR_INCOMPLETE_CHUNKED_ENCODING #414

Closed VisualFox closed 2 months ago

VisualFox commented 2 months ago

Hi there, first thank you for this great piece of software, I love it.

I found an issue with the Alpine container and few potential way to fix it (I can make a PR if needed). I was getting some ERR_INCOMPLETE_CHUNKED_ENCODING will serving some css and javascript file.

This one will be hard to reproduce as it only happen to me on a specific server (I'm going to assume that have to do with limited bandwidth). When a file is large enough and the bandwidth is limited, nginx will write a temporary file in /var/cache/nginx if it cannot access the temporary file it will abruptly terminate the connection and that will generate an ERR_INCOMPLETE_CHUNKED_ENCODING on the client.

@see https://stackoverflow.com/questions/29789268/neterr-incomplete-chunked-encoding-nginx

Currently the Alpine docker file set the permission for /var/cache/nginx to 700 and it need to be set to 715 in order for the nginx worker to manage temporary files. I checked the official nginx docker file and /var/cache/nginx is set to 715. An alternative solution is to give full ownership to nginx for /var/cache/nginx but I like this solution less.

let me know if you need a PR and if you prefer the version where the permission are set to 715 or full ownership if given to the nginx user.

Thank you!

VisualFox commented 2 months ago

I forgot to mention it, but I have no idea is that also affect the non-alpine docker image based on Rocky Linux

kleisauke commented 2 months ago

The Alpine Docker image uses /var/cache/nginx only during configuration; temporary files are stored in shared memory instead. https://github.com/weserv/images/blob/caa4e8e23639caf4873f699bbf11f1b705a53fa4/ngx_conf/nginx.conf#L119-L121

I suspect the shared memory size limit of the Docker containers was not increased, which is set to 64MB by default. The --shm-size flag can be used to increase this limit, we assume it's set to at least 1 GB. https://github.com/weserv/images/blob/caa4e8e23639caf4873f699bbf11f1b705a53fa4/ngx_conf/imagesweserv.conf#L1-L3 https://github.com/weserv/images/blob/caa4e8e23639caf4873f699bbf11f1b705a53fa4/docker/README.md#L9

VisualFox commented 2 months ago

Thank you for coming back to me. I now see that I probably misunderstood how to use this image and at the result I misconfigured it. I was using it to server regular web traffic and generate derivative images so I never included the proxy_temp_path and client_body_temp_path (as I was just replacing the official nginx image by this one, I kept the same original configuration). I'm going to use two separate containers, each one with its own configuration, one for regular traffic (docker official image) the other one for image derivative (weserv).

We can probably close this ticket. Thank you again for you time and this great software.