5

I checked the cache path /usr/local/nginx/proxy_cache. No cache file found after I visit some url many times.

My configuration: ngnix.conf

http {
   include       /etc/nginx/mime.types;

   default_type  application/octet-stream;

   access_log   /var/log/nginx/access.log;

   sendfile        on;
   #tcp_nopush     on;

   #keepalive_timeout  0;
   keepalive_timeout  65;
   tcp_nodelay        on;

   client_body_buffer_size  512k;  


   proxy_temp_file_write_size 128k;  
   proxy_temp_path   /usr/local/nginx/proxy_temp;  
   proxy_cache_path /usr/local/nginx/proxy_cache levels=1:2 keys_zone=content:20m inactive=1d max_size=100m;   

   gzip  on;

   include /etc/nginx/conf.d/*.conf;
   include /etc/nginx/sites-enabled/*;
}

default

server {
listen   80;
server_name  208.115.202.87;


   location  /test {    
     proxy_cache content; 
     proxy_cache_key $host$uri$is_args$args;
         proxy_cache_valid  200 15m;
     proxy_pass  http://aaa.com/;
    }
virsir
  • 14,359
  • 23
  • 71
  • 108

2 Answers2

18

nginx does not cache pages which sets cookies, Check if your pages have a Set-Cookie header.

If necessary, cookies can be ignored with proxy_ignore_headers and suppressed with proxy_hide_header. For example:

proxy_ignore_headers Set-Cookie;
proxy_hide_header Set-Cookie;
Fernando Correia
  • 20,349
  • 10
  • 79
  • 113
digitalPBK
  • 2,621
  • 23
  • 24
  • 2
    http://wiki.nginx.org/HttpProxyModule#proxy_cache The following response headers flag a response as uncacheable unless they are ignored: Set-Cookie Cache-Control containing "no-cache", "no-store", "private", or a "max-age" with a non-numeric or 0 value Expires with a time in the past X-Accel-Expires: 0 – digitalPBK Oct 26 '13 at 03:13
2

You should turn on error logging, and then take a look at that. I had a similar problem with the fastcgi cache, and the issue was the folder permissions.

Adam Heath
  • 4,361
  • 1
  • 33
  • 50