1

I am using nginx 1.8.1 with microcache to cache some php requests on /dev/shm and it's working fine, however, when I reboot the server the cached files are gone (obviously) but nginx still references those in the shared memory (shouldn't it be gone on reboot?).

So what happens is that if I request one page that was cached before, it shows a error 500 and gives me an empty reply.

The same happens if I let nginx cache some pages and then manually delete the physical cached files.

I have to reload nginx in order for it to work again.

I thought that if nginx doesn't find the cache file, it would create a new one. Is this suppose to happen? Do I have to always reload nginx after deleting the cache files manually?

Is there a way for nginx to automatically recreate the file, if it doesn't find the cached file?

Relevant code:

fastcgi_cache_path /dev/shm levels=1:2 use_temp_path=off keys_zone=mcache:16m inactive=600s max_size=512m;

And also:

fastcgi_keep_conn on;
fastcgi_connect_timeout 20s; 
fastcgi_send_timeout 30s; 
fastcgi_read_timeout 30s;
fastcgi_cache_lock   on;
fastcgi_cache_use_stale timeout updating;
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache     $skip_cache;
fastcgi_cache        mcache;
fastcgi_cache_valid 200 301 302  5s;
fastcgi_cache_valid 403 404      5m;
add_header X-Proxy-Cache $upstream_cache_status;

I have:

sendfile off;

But still I need to reload (restart doesn't fix) nginx to regenerate cache. I'm testing this on a vultr 2Gb vm.

1 Answer 1

0

I found the answer :)

On my code:

fastcgi_cache_path /dev/shm levels=1:2 use_temp_path=off keys_zone=mcache:16m inactive=600s max_size=512m;

Specifically this part:

use_temp_path=off 

It works after I delete that part and leave at default. This is because, when you turn it off, it will create a temp folder on the cache directory which should not be deleted when you clear the cache.

When I was doing this:

rm -rf /dev/shm/*

The cache was gone, but also gone was the temp folder... Therefore, nginx could not use it to regenerate the new cached files. One you leave at the default (temp will be somewhere else), even if I delete all cache it will work as intended.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .