Proxy cache passes GET instead of HEAD to upstream

jove4015 nginx-forum at nginx.us
Fri Feb 14 22:11:37 UTC 2014


I'm trying to figure out how to get Nginx to proxy cache HEAD requests as
HEAD requests and I can't find any info on google.

Basically, I have an upstream server in another datacenter, far away, that I
am proxying requests to.  I'm caching those requests, so the next time the
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 file,
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 request
instead.  This means long delays for the application as it downloads all the
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 get
sent through to the upstream as HEAD requests, like one would expect. 
However, turning off the cache defeats the whole purpose of setting this
up.

Is there any way to set up the proxy to the upstream so that it proxies HEAD
requests as HEAD requests, and GET requests as normal, and still caches
responses as well?  Ideally it would cache all GET responses, check against
the cache for HEAD requests, and proxy HEAD requests for objects not in the
cache as HEAD requests (thereby not caching the response, or only caching
the HEAD response as a separate object - ideally the latter but I could live
with the former).

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,247577,247577#msg-247577



More information about the nginx mailing list