Maxim Dounin
December 11, 2014 09:32AM
Hello!

On Thu, Dec 11, 2014 at 03:54:25AM -0500, Cord Beermann wrote:

> Hello,
>
> Due to issues with a backend beyond my influence i need to fix this with
> Nginx.
>
> Root-Cause: A CMS generates empty files on a filesystem which will be later
> filled with content. However: those files are there for some time with 0
> bytes
> and will be served with 200 through a chain of a caching Nginx and a caching
> CDN.
>
> User --> CDN --> Caching Nginx (SlowFS) --> Serving Nginx --> Filesystem.
>
> The Backend-Filesystem is served by a Nginx. Solution could be to serve a
> 404
> for all empty files.

Please note that this is _not_ a solution, as at some point files
will be partially filled with content, and testing that the size
isn't 0 won't help. Rather, it's a workaround which hides the
problem in some cases.

The only _solution_ I see is to fix backend to update files
atomically - e.g., write to a temporaty file, and then rename()
it to a real name.

> I tried with $sent_http_content_length, but it seems to
> be empty in the location where i would need it. Is it possible to use some
> kind of 'test -s' on the file to decide when to send a 404?

This is something possible with embedded perl (and lua, as already
suggested).

> I also tried to tackle it in the caching SlowFS-Nginx, by using
> $upstream_http_content_length in if or map-statements [1]. I can see
> $upstream_http_content_length set in an X-Debug-Header i added, but can't
> get
> it to work to use it to act on it.
>
> if ($upstream_http_content_length = 0) {
> return 404;
> }

This is not going to work as "if" will be executed before the
request is sent to the upstream server.

--
Maxim Dounin
http://nginx.org/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

sending 404 responses for epty objects.

Cord Beermann December 11, 2014 03:54AM

Re: sending 404 responses for epty objects.

itpp2012 December 11, 2014 04:40AM

Re: sending 404 responses for epty objects.

Maxim Dounin December 11, 2014 09:32AM

Re: sending 404 responses for epty objects.

philipp May 04, 2015 07:52AM

Re: sending 404 responses for epty objects.

Maxim Dounin May 04, 2015 10:28AM

Re: sending 404 responses for epty objects.

philipp May 04, 2015 10:45AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 304
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready