HEAD request breaks fastxgi_cache

I have registered with Uptime Robot. You can have it monitor a URL. It
does this by sending a HEAD request every 5 to 10 minutes and checking
for an OK response. This request triggers the fastcgi cache with an
empty content. If I understand the wiki correctly I can’t not cache HEAD
requests (Module ngx_http_fastcgi_module).

The only (dubious) fix this I can see at the moment is to add an IP
exception to the nginx config. However that effectively leaves the site
open to abuse by someone being malicious.

Is there a way I can just cache GET requests? Or requests with body
content size > 0? Or is there a better way?

Posted at Nginx Forum:

You could add $request_method to your cache_key and this would store
those requests in different keys.

Posted at Nginx Forum:

kaspars Wrote:

You could add $request_method to your cache_key
and this would store those requests in different
keys.

Yes, of course. Thank you!

Posted at Nginx Forum:

kaspars Wrote:

Btw, what kind of cache invalidation are you
using, if any? Is it only time based or do you use
nginx no_cache and cache_bypass directives
(Module ngx_http_fastcgi_module
ache) as well?

It is a WordPress configuration, which relies on the
nginx-proxy-cache-purge plugin to purge pages on update.

/etc/nginx/my.conf# cat wordpress-fastcgi-cache.conf
# Segment to include in all WP installs.
# Configures php-fpm (socket) with fastcgi caching.
    set $nocache "";
    if ($http_cookie ~
(comment_author_.*|wordpress_logged_in.*|wp-postpass_.*)) {
      set $nocache "Y";
    }

    fastcgi_pass  unix:/usr/local/var/run/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param CONTENT-LENGTH  $content_length;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_script_name;
    include fastcgi_params;

    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_cache_key       $request_method$host$request_uri;
    fastcgi_cache           WORDPRESS;
    fastcgi_cache_valid     200 10m;
    fastcgi_ignore_headers  Expires Cache-Control;
    fastcgi_cache_bypass    $nocache;
    fastcgi_no_cache        $nocache;
/etc/nginx/my.conf# nginx -V
nginx version: nginx/0.8.53
built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
TLS SNI support enabled
configure arguments: --conf-path=/etc/nginx/nginx.conf
--error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid
--lock-path=/var/lock/nginx.lock
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/lib/nginx/body
--http-proxy-temp-path=/var/lib/nginx/proxy
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi --with-debug
--with-http_stub_status_module --with-http_flv_module
--with-http_ssl_module --with-http_dav_module
--with-http_gzip_static_module --with-http_realip_module --with-mail
--with-mail_ssl_module --with-ipv6
--add-module=/usr/src/nginx/cache_purge

Posted at Nginx Forum:

Btw, what kind of cache invalidation are you using, if any? Is it only
time based or do you use nginx no_cache and cache_bypass directives
(Module ngx_http_fastcgi_module) as well?

Posted at Nginx Forum: