nginx serving corrupt images

Maxim Dounin mdounin at mdounin.ru
Thu Feb 23 00:17:00 UTC 2023


Hello!

On Wed, Feb 22, 2023 at 02:46:29PM -0500, Saint Michael wrote:

> It's not a misconfiguration, is a huge bug.
> A wasted two days of sleep for something that is 100% a bug.
> Please read here:
> https://laracasts.com/discuss/channels/general-discussion/homestead-nginx-serving-wrong-images-and-only-cut-in-the-middle
> He mentions the same exact problem and also he points to
> https://tech.blog.aknin.name/2011/11/04/nginxgzip-module-might-silently-corrupt-data-upon-backend-failure/
> where the author says that Niginx will not fix it.
> So he already tried he was rebuffed.

The fun fact is that the referenced article doesn't state "will 
not fix", but rather "not a top priority".  Further, proper error 
propagation is available in nginx for about 10 years now, since 
2013 (http://hg.nginx.org/nginx/rev/d3eab5e2df5f, nginx 1.5.3).  
Quoting CHANGES:

    *) Change: now after receiving an incomplete response from a backend
       server nginx tries to send an available part of the response to a
       client, and then closes client connection.

As long as nginx have an information about an error, it will 
preserve this information and propagate it to the client.

Also note that it is only expected to make a difference if you are 
using nginx as a proxy, not to directly serve files.  And only in 
case of errors.  That is, if you are seeing the behaviour 
described, it might be a good idea to focus on the errors in the 
first place.

I don't think it's anyhow related though, as switching gzip off 
and back on, as seems to be "the fix" described in the first link, 
is not going to help with anything.  The important part is likely 
"restarted the server", so I would rather assume that "the server" 
(not sure if it refers to nginx or the whole server) was using an 
incorrect configuration and/or was out of some resources, and 
restart fixed it.

Summing the above, if you want to find out what goes wrong in your 
case - you may want to provide more details.  If you don't, nobody 
will be able to do it, unfortunately.

The most basic thing I would recommend in the first place is to 
look into nginx error log, it is likely to contain important 
information if something goes wrong.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list