# Fastcgi\_cache\_path empty

**URL:** <https://www.ruby-forum.com/t/fastcgi-cache-path-empty/238493>\
**Category:** NGINX\
**Created:** [January 13, 2014, 11:13pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-path-empty/238493 "2014-01-13T23:13:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [January 13, 2014, 11:13pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-path-empty/238493/1 "2014-01-13T23:13:53Z")

</div>

I wanted to try fastcgi\_cache on my nginx 1.5.8 as shown here  
[http://seravo.fi/2013/optimizing-web-server-performance-with-nginx-and-php](http://seravo.fi/2013/optimizing-web-server-performance-with-nginx-and-php)

In nginx conf, http section, I added:

fastcgi\_cache\_path /var/cache/nginx levels=1:2 keys\_zone=microcache:10m  
max\_size=1000m inactive=60m;

In server section:  
set $cache\_uri $request\_uri;

```
# POST requests and urls with a query string should always go to PHP
if ($request_method = POST) {
    set $cache_uri 'null cache';
}
if ($query_string != "") {
    set $cache_uri 'null cache';
}

# Don't cache uris containing the following segments
if ($request_uri ~*

```

“(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.\*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]±sitemap([0-9]+)?.xml)”)  
{  
set $cache\_uri ‘null cache’;  
}

```
# Don't use the cache for logged in users or recent commenters
if ($http_cookie ~*

```

“comment\_author|wordpress\_[a-f0-9]+|wp-postpass|wordpress\_logged\_in”) {  
set $cache\_uri ‘null cache’;  
}

```
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    include fastcgi.conf;
    fastcgi_pass unix:/var/run/php5-fpm.sock;

    ##
    # Fastcgi cache
    ##
    set $skip_cache 1;
            if ($cache_uri != "null cache") {
                add_header X-Cache-Debug "$cache_uri $cookie_nocache

```

$arg\_nocache$arg\_comment $http\_pragma $http\_authorization";  
set $skip\_cache 0;  
}  
fastcgi\_cache\_bypass $skip\_cache;  
fastcgi\_cache\_key  
$scheme$host$request\_uri$request\_method;  
fastcgi\_cache\_valid any 8m;  
fastcgi\_cache\_bypass $http\_pragma;  
fastcgi\_cache\_use\_stale updating error timeout  
invalid\_header http\_500;

```
}

```

I chowned /var/cache/nginx to www-data user (and group) and chmodded it to  
775.  
I restarted nginx but the folder is always empty. Is it normal? How can I  
test if fastcgi\_cache is working?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![lorenzo\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lorenzo\_r](https://www.ruby-forum.com/u/lorenzo_r)\
**Post date:** [January 16, 2014, 8:20pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-path-empty/238493/2 "2014-01-16T20:20:33Z")

</div>

No one? 🙂

2014/1/13 Lorenzo R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![lorenzo\_r](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/aca169/32.png) [@lorenzo\_r](https://www.ruby-forum.com/u/lorenzo_r)\
**Post date:** [January 16, 2014, 9:07pm UTC](https://www.ruby-forum.com/t/fastcgi-cache-path-empty/238493/3 "2014-01-16T21:07:52Z")

</div>

I think ( it’s hard to read ) that you’re not telling the site which  
http cache to use ( fastcgi\_cache microcache; ).

On my systems ( I’m looking at an Amazon one so RH  
based ), /var/cache/nginx is already in use. I set  
up /var/cache/nginx\_fastcgi instead, which is not empty.

(1GB is way too big btw).

I created a file /etc/nginx/microcache, containing

–8\<–

# Setup var defaults

set $no\_cache “”;

# If non GET/HEAD, don’t cache & mark user as uncacheable for 1 second

via cookie  
if ($request\_method !~ ^(GET|HEAD)$) {  
set $no\_cache “1”;  
}

# Drop no cache cookie if need be

# (for some reason, add\_header fails if included in prior if-block)

if ($no\_cache = “1”) {  
add\_header Set-Cookie “\_mcnc=1; Max-Age=2; Path=/”;  
add\_header X-Microcachable “0”;  
}

# Bypass cache if no-cache cookie is set

if ($http\_cookie ~\* “\_mcnc”) {  
set $no\_cache “1”;  
}

# Bypass cache if flag is set

fastcgi\_no\_cache $no\_cache;  
fastcgi\_cache\_bypass $no\_cache;  
fastcgi\_cache microcache;  
fastcgi\_cache\_key “$scheme$request\_method$host$request\_uri  
$http\_if\_modified\_since$http\_if\_none\_match”;  
fastcgi\_cache\_valid 404 30m;  
fastcgi\_cache\_valid 200 10s;  
fastcgi\_max\_temp\_file\_size 1M;  
fastcgi\_cache\_use\_stale updating;  
fastcgi\_pass\_header Set-Cookie;  
fastcgi\_pass\_header Cookie;  
fastcgi\_ignore\_headers Cache-Control Expires Set-Cookie;  
–8\<–  
(this only stores for 10 seconds BTW, and the cache key is designed for  
a magento site).

And included it in the location blocks that would use it, ie

location ~\* .php$

This way the config becomes much more readable.

hth,

Steve

On Thu, 2014-01-16 at 20:19 +0100, Lorenzo R. wrote:

> ```
> set $cache_uri 'null cache';
> set $cache_uri 'null cache';
> try_files $uri =404;
> add_header X-Cache-Debug "$cache_uri
> invalid_header http_500;
> 
> ```
> 
> * * *
> 
> nginx mailing list  
> removed\_email\_address@domain.invalid  
> [nginx Info Page](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Steve H. BSc(Hons) MIITP

> **[Linux & Admin Support Services | "Services provided by people who are...](https://www.greengecko.co.nz/)**
>
> Offers linux support services, systems and database administration, consultancy and the full development lifecycle for open source - based solutions

Linkedin: [http://www.linkedin.com/in/steveholdoway](http://www.linkedin.com/in/steveholdoway)  
Skype: sholdowa
