Proxy cache passes GET instead of HEAD to upstream

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

On Friday 14 February 2014 17:11:37 jove4015 wrote:
[…]

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).

You can set:

proxy_cache_methods GET;

in this case HEAD requests will bypass cache.

wbr, Valentin V. Bartenev

Hello!

On Sat, Feb 15, 2014 at 02:23:26AM +0400, Valentin V. Bartenev wrote:

You can set:

proxy_cache_methods GET;

in this case HEAD requests will bypass cache.

No, this won’t work. HEAD and GET requests are always added to
the proxy_cache_methods mask.


Maxim D.
http://nginx.org/

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs