Welcome! Log In Create A New Profile

Advanced

Proxy cache passes GET instead of HEAD to upstream

February 14, 2014 05:11PM
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).
Subject Author Posted

Proxy cache passes GET instead of HEAD to upstream

jove4015 February 14, 2014 05:11PM

Re: Proxy cache passes GET instead of HEAD to upstream

Valentin V. Bartenev February 14, 2014 05:24PM

Re: Proxy cache passes GET instead of HEAD to upstream

Maxim Dounin February 17, 2014 08:46AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 244
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready