sending 404 responses for epty objects.

Cord Beermann nginx-forum at
Thu Dec 11 08:54:25 UTC 2014


Due to issues with a backend beyond my influence i need to fix this with

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
and will be served with 200 through a chain of a caching Nginx and a caching

User --> CDN --> Caching Nginx (SlowFS) --> Serving Nginx --> Filesystem.

The Backend-Filesystem is served by a Nginx. Solution could be to serve a
for all empty files. I tried with $sent_http_content_length, but it seems
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?

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
it to work to use it to act on it.

	if ($upstream_http_content_length = 0) {
	  return 404;

I found the discussion about 'using $upstream* variables inside map
but even if i would get this to work it wouldn't be enough as i need to
signal the CDN in front (with some headers) that it also should not cache
empty response. Best would be to generate a 404 if the upstream-object is

So maybe someone here has an idea how to tackle this.


[1] like in

Posted at Nginx Forum:,255421,255421#msg-255421

More information about the nginx mailing list