Nginx Cache Valid till - Help

Hi,

I have a issue my nginx cofig is working ok just i want cache to clear
only once in 15 days.
But it is clearing everyday and new images showing on homepage ( we use
random images hence on each refresh its new)
however with nginx it needs to show same page and images etc picked from
cache.
It works ok for 24 hours then again refreshes all content…as if cache
is clear.

Here is Nginx conf

user nginx;
worker_processes 16;
worker_rlimit_nofile 100000;

error_log /var/log/nginx/error.log crit;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;

pid /var/run/nginx.pid;

events {
worker_connections 102400;
use epoll;
}

http {
proxy_cache_path /var/lib/nginx/tmp/cache1 levels=1:2
keys_zone=proxy_cache1:16m max_size=20g inactive=1d;
proxy_cache_path /var/lib/nginx/tmp/cache2 levels=1:2
keys_zone=proxy_cache2:16m max_size=40g inactive=30d;
proxy_temp_path /var/lib/nginx/tmp/proxy;

include       /etc/nginx/mime.types;
default_type  application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local]

“$request” ’
'$status $body_bytes_sent “$http_referer” ’
‘“$http_user_agent” “$http_x_forwarded_for”’;

access_log  off;# /var/log/nginx/access.log  main;

sendfile        on;
tcp_nopush      on;
tcp_nodelay     on;
server_tokens   off;
gzip            on;
gzip_static     on;
gzip_comp_level 5;
gzip_min_length 1024;
keepalive_timeout  65;

Here is cache inc

access_log off;
location / {
proxy_pass http://96.30.58.176:80;
include /etc/nginx/generic.inc;
proxy_ignore_headers “Cache-Control” “Expires”;
proxy_cache_key
“$server_name$scheme$proxy_host$uri$is_args$args$cookie_sid”;
proxy_cache proxy_cache1;
proxy_cache_use_stale updating error timeout invalid_header
http_500;
proxy_cache_valid 15d;
}

location ~*

^.+.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar)$ {
proxy_pass http://96.30.58.176:80;
include /etc/nginx/generic.inc;
proxy_ignore_headers “Cache-Control” “Expires”;
proxy_cache_key “$server_addr:$server_port$request_uri”;
proxy_cache proxy_cache2;
proxy_cache_use_stale updating error timeout invalid_header
http_500;
proxy_cache_valid 15d;
}

Here is site.conf in called conf.d called

server {
listen 96.30.58.176:8080;
server_name www.site.com;
include /etc/nginx/cache.inc;
location /nginx_status {
stub_status on;
}
if ($http_host ~* “^site.com$”){
set $rule_0 1$rule_0;
}
if ($rule_0 = “1”){
rewrite ^/(.*)$ Custom Application Development Software for Business - Salesforce.com permanent;
break;
}
}

Regards

Posted at Nginx Forum:

Have you tried setting the following in your location blocks?

expires 15d;

Posted at Nginx Forum:

Hello!

On Sun, Nov 14, 2010 at 12:10:59AM -0500, rajivv wrote:

I have a issue my nginx cofig is working ok just i want cache to clear
only once in 15 days.
But it is clearing everyday and new images showing on homepage ( we use
random images hence on each refresh its new)
however with nginx it needs to show same page and images etc picked from
cache.
It works ok for 24 hours then again refreshes all content…as if cache
is clear.

I guess by “random images” you mean random in your
html code, right?

[…]

http {
proxy_cache_path /var/lib/nginx/tmp/cache1 levels=1:2
keys_zone=proxy_cache1:16m max_size=20g inactive=1d;
proxy_cache_path /var/lib/nginx/tmp/cache2 levels=1:2
keys_zone=proxy_cache2:16m max_size=40g inactive=30d;
proxy_temp_path /var/lib/nginx/tmp/proxy;

[…]

location / {

[…]

proxy_cache_key

“$server_name$scheme$proxy_host$uri$is_args$args$cookie_sid”;
proxy_cache proxy_cache1;

Note that your cache key for html contains $cookie_sid. It looks
like session cookie, and probably per-user and likely to expire
somewhere earlier than after 15 days.

Also note that it uses proxy_cache1 which has 1d inactivity
timeout, i.e. if no requests for a given key (with $cookie_sid)
seen by nginx within 1d cache entry will be removed.

Maxim D.

I will try inactive at 15 days and see do i need to restart nginx…

Posted at Nginx Forum:

What to do about session cookie ?

Posted at Nginx Forum: