本文介绍了为什么Nginx不缓存我的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了缓存路径/usr/local/nginx/proxy_cache.我多次访问一些URL后找不到缓存文件.

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

我的配置:ngnix.conf

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/*;
}

默认

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/;
    }

推荐答案

nginx不缓存设置cookie的页面,检查您的页面是否具有Set-Cookie标头.

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

如有必要,可以使用 proxy_ignore_headers 忽略Cookie,并使用 proxy_hide_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;

这篇关于为什么Nginx不缓存我的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 06:10