Avoid caching FPM response by content-length

19 views
Skip to first unread message

Andrei ZeeGiant

unread,
Apr 16, 2018, 10:32:55 AM4/16/18
to openresty-en
Hello!

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 somewhere along these lines.. but I'm not entirely certain how

location ~ .php$ {
[..]
body_filter_by_lua_block {
 if ngx.var.request_uri == "/" then
  if ngx.var.http_content_length < 5120 then
    ngx.status = 503
    return ngx.exit(503)
  fi
 fi
}
}

Thanks!
Reply all
Reply to author
Forward
0 new messages