# HEAD request breaks fastxgi\_cache

**URL:** <https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347>\
**Category:** NGINX\
**Created:** [February 18, 2011, 6:11am UTC](https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347 "2011-02-18T06:11:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [February 18, 2011, 6:11am UTC](https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347/1 "2011-02-18T06:11:59Z")

</div>

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](http://wiki.nginx.org/HttpFcgiModule#fastcgi_cache_methods)).

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:

> **[HEAD request breaks fastxgi\_cache](https://forum.nginx.org/read.php?2,176381,176381#msg-176381)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![graq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@graq](https://www.ruby-forum.com/u/graq)\
**Post date:** [February 18, 2011, 8:58am UTC](https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347/2 "2011-02-18T08:58:18Z")

</div>

You could add $request\_method to your cache\_key and this would store  
those requests in different keys.

Posted at Nginx Forum:

> **[Re: HEAD request breaks fastxgi\_cache](https://forum.nginx.org/read.php?2,176381,176392#msg-176392)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![graq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@graq](https://www.ruby-forum.com/u/graq)\
**Post date:** [February 18, 2011, 10:23am UTC](https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347/3 "2011-02-18T10:23:32Z")

</div>

## 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:  
[http://forum.nginx.org/read.php?2,176381,176405#msg-176405](http://forum.nginx.org/read.php?2,176381,176405#msg-176405)

---

<div class="post-metadata">

**Author:** ![graq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@graq](https://www.ruby-forum.com/u/graq)\
**Post date:** [February 18, 2011, 1:10pm UTC](https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347/4 "2011-02-18T13:10:40Z")

</div>

## 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  
> ([GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/HttpFcgiModule#fastcgi_no_c)  
> ache) as well?

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

```auto
/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;
```

```auto
/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
```

> **[Nginx Proxy Cache Purge](https://wordpress.org/plugins/nginx-proxy-cache-purge/)**
>
> Purges the nginx proxy cache when you publish or update a post or page.

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,176381,176439#msg-176439](http://forum.nginx.org/read.php?2,176381,176439#msg-176439)

---

<div class="post-metadata">

**Author:** ![graq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@graq](https://www.ruby-forum.com/u/graq)\
**Post date:** [February 18, 2011, 10:48am UTC](https://www.ruby-forum.com/t/head-request-breaks-fastxgi-cache/203347/5 "2011-02-18T10:48:35Z")

</div>

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](http://wiki.nginx.org/HttpFcgiModule#fastcgi_no_cache)) as well?

Posted at Nginx Forum:

> **[Re: HEAD request breaks fastxgi\_cache](https://forum.nginx.org/read.php?2,176381,176408#msg-176408)**
>
> 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...
