I have an odd upstream application (out of my control) which intermittently responds with incomplete pages, and a 200.. This causes blank pages to appear in cache. Is there a way to avoid caching a fastcgi/fpm backend response if the content-length is lower than 5kb for example?
I'm guessing this can be done using Lua along these lines, but I'm not entirely certain :)
location ~ .php$ {
[..]
body_filter_by_lua_block {
if ngx.var.uri == "/" then
if ngx.var.http_content_length < 5120 then
ngx.status = 503
return ngx.exit(503)
fi
fi
}
}
Thanks everyone!