Welcome! Log In Create A New Profile

Advanced

My way to force cache expire

Simone fumagalli
June 24, 2010 11:14AM
I've Nginx in front of my CMS that cache requests without cookie (anonymous visitors) while other requests (logged in users) are passed to the backend.

The conf look like this (only relevant parts) :

---------------------------------------------------------------------

proxy_cache_path /usr/local/www/cache/myapp/html levels=1:2 keys_zone=MYAPP_HTML_CACHE:10m inactive=30m max_size=2g;

server {

server_name www.myapp.com
listen 111.222.333.444:80;

proxy_cache_key "$scheme://$host$request_uri";
proxy_cache_valid 200 20m;

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_temp_path /usr/local/tmp;

location / {

# If logged in, don't cache.
if ($http_cookie ~* "my_app_cookie" ) {
set $do_not_cache 1;
}

proxy_cache_key "$scheme://$host$request_uri$do_not_cache";
proxy_cache MYAPP_HTML_CACHE;
proxy_pass http://ALL_backend;

}

}

---------------------------------------------------------------------


Everything works but now I'm looking for a way to delete cached pages when they are updated from the backend
I thought I could make an http get from my backend with a particular cookie (backend_cookie) to the URL of the page I want to update.
The backend is configured in a way so that HTTP requests pass by the proxy and are treated like external request.

So, do you think this setup can work ?

I've added only the 3 line with # at the beginning

---------------------------------------------------------------------

proxy_cache_path /usr/local/www/cache/myapp/html levels=1:2 keys_zone=MYAPP_HTML_CACHE:10m inactive=30m max_size=2g;

server {

server_name www.myapp.com
listen 111.222.333.444:80;

proxy_cache_key "$scheme://$host$request_uri";
proxy_cache_valid 200 20m;

proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_temp_path /usr/local/tmp;

location / {

# Do not cache for logged user
if ($http_cookie ~* "my_app_cookie" ) {
set $do_not_cache 1;
}

# if ($http_cookie ~* "my_backend_cookie" ) {
# proxy_cache_valid 200 0m;
# }

proxy_cache_key "$scheme://$host$request_uri$do_not_cache";
proxy_cache MYAPP_HTML_CACHE;
proxy_pass http://ALL_backend;

}

}

---------------------------------------------------------------------

Let me know

--
Simone Fumagalli

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

My way to force cache expire

Simone fumagalli June 24, 2010 11:14AM

Re: My way to force cache expire

Ryan Malayter June 24, 2010 11:26AM

Re: My way to force cache expire

Simone fumagalli June 24, 2010 11:28AM

Re: My way to force cache expire

Piotr Sikora June 24, 2010 11:48AM

Re: My way to force cache expire

Simone fumagalli June 24, 2010 12:14PM

Re: My way to force cache expire

Piotr Sikora June 24, 2010 11:50AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 191
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready