0

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!

4
  • there isn't such option... you could try a little hack by deleting empty pages from cache? Apr 16, 2018 at 13:37
  • The cache storage can get rather large. I'd rather avoid the IO all together. I'm thinking Lua might be a better fit in this case but I'm not sure how to proceed yet
    – Andrei
    Apr 16, 2018 at 13:46
  • Do you have to use nginx? nuster cache server(github.com/jiangwenyuan/nuster) can do this: cache-rule cache_5kb if { res.hdr_val(Content-Length) gt 5000 } ` Apr 17, 2018 at 0:38
  • I'm using a cluster of openresty servers, so yeah it's a requirement :)
    – Andrei
    Apr 21, 2018 at 17:41

0

You must log in to answer this question.

Browse other questions tagged .