I’m trying to figure out how to get Nginx to proxy cache HEAD requests
HEAD requests and I can’t find any info on google.
Basically, I have an upstream server in another datacenter, far away,
am proxying requests to. I’m caching those requests, so the next time
request comes in, we don’t have to go to the other datacenter to get the
file. Sometimes, the application needs to check the existence of a
but doesn’t actually need to read the file, so we wanted to set it up to
make a HEAD request for the file. When nginx gets the HEAD request, and
forwards to the upstream server, it sends the upstream server a GET
instead. This means long delays for the application as it downloads all
data for all the files it is checking (some 50MB of files), when it only
needs to know if the files are there.
I do notice that if I turn off the proxy cache, then the HEAD requests
sent through to the upstream as HEAD requests, like one would expect.
However, turning off the cache defeats the whole purpose of setting this
Is there any way to set up the proxy to the upstream so that it proxies
requests as HEAD requests, and GET requests as normal, and still caches
responses as well? Ideally it would cache all GET responses, check
the cache for HEAD requests, and proxy HEAD requests for objects not in
cache as HEAD requests (thereby not caching the response, or only
the HEAD response as a separate object - ideally the latter but I could
with the former).
Posted at Nginx Forum: