Nginx, static files and local caching

I’m currently using nginx for my static files.
Apache is still being used to serve my dynamic PHP scripts.
This configuration works perfectly

Is it possible to cache the static files served bij nginx?
Because I’m using NFS, and when the files aren’t cache my NFS servers
gets a very high load.

I’ve found something with try_files, but I don’t think that works
because it looks like it uses Apache to serve the static files.
I searched all forums but I can’t found a good solution.

Who can help me?

Posted at Nginx Forum:

make apache serve static pages and cache them with proxy_cache in nginx.

2010/2/10 rkappert [email protected]:

Is it possible to cache the static files served bij nginx?
Because I’m using NFS, and when the files aren’t cache my NFS servers gets
a very high load.

ngx_slowfs_cache was created exactly to solve this problem:
http://labs.frickle.com/nginx_ngx_slowfs_cache

Best regards,
Piotr S. < [email protected] >

Shouldn’t NFS be caching already?

Should it? It’s remote location which can be modified by other systems.

Given you have free ram available on the
nginx machine, it should be caching the files in disk cache. Why the
redundancy?

Well, for one, free local disk space is probably order of magnitude
bigger
than buffer cache.

Best regards,
Piotr S. < [email protected] >

Shouldn’t NFS be caching already? Given you have free ram available on
the
nginx machine, it should be caching the files in disk cache. Why the
redundancy?

On Wed, Feb 10, 2010 at 12:29 PM, Piotr S.
[email protected]wrote:

Shouldn’t NFS be caching already?

Should it? It’s remote location which can be modified by other systems.

Yes it should. If it isn’t your implementation is not working properly.

Given you have free ram available on the

nginx machine, it should be caching the files in disk cache. Why the
redundancy?

Well, for one, free local disk space is probably order of magnitude bigger
than buffer cache.

I can’t disagree with this, It’s use as a remote to local filesystem
cache
would be useful. Does it have stateful checks to determine if files are
changed?

Hi Piotr,

I tried this module, but it seems the /tmp/nginx folder is always empty.
Is
there any i’ve missed?

Yes it should.

NFS cache is/was broken, so it’s open discussion, but not exactly on
topic.

If it isn’t your implementation is not working properly.

ngx_slowfs_cache isn’t NFS implementation, it’s caching mechanism.

I can’t disagree with this, It’s use as a remote to local filesystem cache
would be useful. Does it have stateful checks to determine if files are
changed?

Like I said on IRC: it’s cache by nginx definition (make local copy and
serve it unconditionally until it expires), so no, it doesn’t check if
original file was modified.

Best regards,
Piotr S. < [email protected] >

Here’s my config

http {

slowfs_cache_path /data/cache levels=1:2 keys_zone=fastcache:10m;
slowfs_temp_path /data/temp 1 2;

server {
listen 80;
root /var/www;

    location / {
        slowfs_cache        fastcache;
        slowfs_cache_key    $uri;
        slowfs_cache_valid  1d;
    }

    location ~ /purge(/.*) {
        allow               127.0.0.1;
        deny                all;
        slowfs_cache_purge  fastcache $1;
    }

}

}

Sorry my mistake… please ignore the previous email… it seems to be
working
:slight_smile:

Is there any way I can if user is accessing my cache file?

Is there any way I can if user is accessing my cache file?

Can you see it in logs?
Yes, you can use $slowfs_cache_status for that.

Best regards,
Piotr S. < [email protected] >

Hi,

I tried this module, but it seems the /tmp/nginx folder is always empty.
Is
there any i’ve missed?

I can’t really answer that question without you posting your
configuration.

Best regards,
Piotr S. < [email protected] >