Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#729 closed defect (invalid)

proxy_cache_methods is ignored

Reported by: Alan Orth Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.7.x
Keywords: Cc:
uname -a: Linux web01 3.13.0-46-generic #77-Ubuntu SMP Mon Mar 2 18:23:39 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.7.10
built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/ --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed' --with-ipv6


I am attempting to only cache GET requests. Here is the relevant proxy_cache configuration:

proxy_cache_key $scheme$request_method$host$request_uri;
proxy_cache_methods GET;

Generating an explicit HEAD request:

$ http HEAD http://web01/

Results in a cache entry with the following key:

KEY: httpsHEADweb01/

I can't figure out how to instruct nginx to stop caching HEAD requests.

Change History (2)

comment:1 by Alan Orth, 5 years ago

Oh, my bad. The docs mention this:

“GET” and “HEAD” methods are always added to the list, though it is recommended to specify them explicitly.

Seems the best thing to do is add $request_method to the proxy_cache_key so you don't serve HEAD cache hits for GET requests.


comment:2 by Valentin V. Bartenev, 5 years ago

Resolution: invalid
Status: newclosed

Actually nginx doesn't cache HEAD responses. Instead, when it receives cacheable HEAD request it sends GET request (not HEAD one!) to an upstream server and caches the response.

And yes, the docs mentions that “GET” and “HEAD” methods are always added to the list.

Version 0, edited 5 years ago by Valentin V. Bartenev (next)
Note: See TracTickets for help on using tickets.