FRiCKLE Labs & yo.se pres. ngx_cache_purge

Hello,
ngx_cache_purge is a module which adds ability to purge content from
FastCGI
and proxy caches. This is rewrite of well-tested cache_purge patch
(kindly
funded by yo.se), so hopefully this short introduction is enough :wink:

You can download it at usual place:
http://labs.frickle.com/nginx_ngx_cache_purge/

GitHub repository is available at:

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

Version 1.1 is now available at:
http://labs.frickle.com/nginx_ngx_cache_purge/

GitHub repository is available at:
http://github.com/FRiCKLE/ngx_cache_purge/

Changes:
2010-06-08 VERSION 1.1
* Fix compatibility with nginx-0.8.40+.

* Add ability to purge content from uWSGI's cache.

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

Thanks.

My English is not good and please forgive my bad grammer.

I want only .jpg and .gif be cached, so I wrote:

location ~ .*.(jpg|gif)$
{
proxy_cache cache1;
proxy_cache_valid 200 304 15m;
proxy_cache_key $host$uri$is_args$args;
proxy_pass http://backend;
}

location /
{
proxy_pass http://backend;
}

and here comes a problem: you can’t purge any more, browser show: 404

Can you help me?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,98939#msg-98939

Hi,
You don’t have any purge location, so this can’t work. Please add:

location ~ /purge(/.*) {
proxy_cache_purge cache1 $host$1$is_args$args;
}

before “location ~ .*.(jpg|gif)$”.

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

And, how can I don’t cache a path-like url ? i.e., http://www.test.com/
or http://www.test.com/path/

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,98947#msg-98947

Hi,
like I said before, you need to put “location ~ /purge(/.)" before
"location ~ .
.(jpg|gif)$”.

In your current configuration “http://www.test.com/purge/1.gif” is
served by
“location ~ .*.(jpg|gif)$”. This is because both regexp locations match
your query and in such case nginx picks the first one from the top.

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

THANK YOU VERY MUCH!

What an simple solution it is.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,99195#msg-99195

Thank you for your reply.

I mean everything is ok before I limited .jpg and .gif to be cached.
So I didn’t write all configurations here.
Then, I give the full version before and current for you to help me.

Version Ok

I visited http://www.test.com/1.gif,

and purge it by visiting, http://www.test.com/purge/1.gif

It’s ok, show: Successful purge …

##########################################################
server {
server_name www.test.com;
listen 80;

    location / {
            proxy_cache cache1;
            proxy_cache_valid 200 304 15m;
            proxy_cache_key $host$uri$is_args$args;
            proxy_pass http://backend;
    }

    location ~ .*\.(php)?$
    {
            proxy_pass http://backend;
    }

    location ~ /purge(/.*)
    {
            proxy_cache_purge    cache1   $host$1$is_args$args;
    }
}

Version not ok

This can’t be purged, show: 404

and I’m sure I visited http://www.test.com/1.gif again before I

purge.

It’s in cache indeed, because I can see the picture in my browser

(with F5, and Ctrl+F5) even after I delete 1.gif from that server.
########################################################
server {
server_name www.test.com;
listen 80;

    access_log logs/proxy.log;

    location ~ .*\.(jpg|gif)$ { # I want only jpg/gif to be cached
            proxy_cache cache1;
            proxy_cache_valid 200 304 15m;
            proxy_cache_key $host$uri$is_args$args;
            proxy_pass http://backend;
    }

    location / # All others not cached
    {
            proxy_pass http://backend;
    }

    location ~ /purge(/.*)
    {
            proxy_cache_purge    cache1   $host$1$is_args$args;
    }
}

Thank you, I thought you can repeat this problem easily.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,99187#msg-99187

Version 1.2 is now available at:
http://labs.frickle.com/nginx_ngx_cache_purge/

GitHub repository is available at:
http://github.com/FRiCKLE/ngx_cache_purge/

Changes:
2010-08-11 VERSION 1.2
* Fix various build scenarios with disabled upstream modules.
Reported by Johan Bergstroem.

* Add ability to purge content from SCGI's cache.
  Requested by Johan Bergstroem.

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

here is my conf:
fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2
keys_zone=DIGG:10m inactive=2m;

location /
{
fastcgi_cache DIGG;
fastcgi_cache_key $host$uri$is_args$args;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_min_uses 2;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_pass unix:/tmp/php-cgi.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location ~ /purge(/.*)
{
allow 127.0.0.1;
deny all;
fastcgi_cache_purge DIGG $host$1$is_args$args;
}
nginx -t don’t returns any error.
but when i visit http://mydomain/purge/xxx.jpg, it returns me a 404
page.
i checked the error log and found this:

2010/10/11 05:04:25 [emerg] 8915#0: unknown directive
“fastcgi_cache_purge” in /usr/local/nginx/conf/nginx.conf:27

is there anybody help me? thanks a lot.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,139639#msg-139639

hi Piotr,
i used nginx 0.75 before, and compile ngx_cache_purge with nginx 0.85.2,
after ./configure --add-module=…/ngx_cache_purge-1.2 …(my own
parameters) and make, i didn’t run a make install and just cp objs/nginx
covering the old one. it’s general method when i upgrade the nginx. i
found there is a file named ngx_cache_purge_module.o in the directory
objs/addon/ngx_cache_purge-1.2, but i don’t know where should i cp it
to. could you please tell me how to install your mod with a running
nginx?
thanks a lot
regards
solo

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,139710#msg-139710

Hi,
did you restart nginx after that? Reload isn’t sufficient.

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

hi piotr,
sure, i have restarted nginx for many times. but it don’t work well now
still…
need i copy ngx_cache_purge_module.o to main dir of nginx? or is there
any way to check whether your mod has been compiled with nginx well?
regards
solo

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,139739#msg-139739

Hi,

2010/10/11 05:04:25 [emerg] 8915#0: unknown directive
“fastcgi_cache_purge” in /usr/local/nginx/conf/nginx.conf:27

You are not using nginx compiled with ngx_cache_purge module.

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

Hi,

need i copy ngx_cache_purge_module.o to main dir of nginx?

No, this is compile-time object file. You don’t need to worry about it.

or is there
any way to check whether your mod has been compiled with nginx well?

nginx -V

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

hi piotr,
i know this line, and it returns me:

nginx version: nginx/0.8.52
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx
–with-http_stub_status_module --with-http_ssl_module
–add-module=…/ngx_cache_purge-1.2

i think i can’t determine what’s wrong with it still…
regards
solo

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,139767#msg-139767

hi piotr,
i’m very sure i’m running the certain nginx, because i’m very puzzled so
that i delete all old version…
regards
solo

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,140028#msg-140028

Hi,
both of your outputs: “nginx -V” and “nginx -t” suggest that nginx is
compiled with “fastcgi_cache_purge” support.

Are you sure that you’re running the same nginx binary as your init.d
script? What happens when you execute nginx binary yourself (without
using
init.d or other scripts)?

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

hi piotr,
i have no idea with this case, and have to reinstall whole nginx, it
works well now, thanks a lot for your help.
i don’t know why, but it works now…
regards
solo

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,140044#msg-140044

hi piotr,
could you please help me one more question? is it useful to cache a php
script in fastcgi_cache? in other words, need i disable fastcgi cache
for all php script? thanks a lot
regards
solo

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,39564,140052#msg-140052

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs