Nginx缓存以及反向代理缓存设置

expires指令

(1).expires [time]

server {
        listen   90;
        server_name  localhost;
        
        location /czj {
            root  /home;
            expires 10s ;
            }
   }

在location模块中配置expires 表示缓存的失效时间为10s .

(2). expires @[time]

server {
        listen   90;
        server_name  localhost;
        
        location /czj {
            root  /home;
            expires @6h10m ;
            }
   }

配置expires @6h10m 表示缓存到6点10分就会失效.
(3). expires -[time]

server {
        listen   90;
        server_name  localhost;
        
        location /czj {
            root  /home;
            expires -1h ;
            }
   }

配置expires -1h表示在当前时间点之前的一个小时缓存失效 .
(4). expires epoch

server {
        listen   90;
        server_name  localhost;
        
        location /czj {
            root  /home;
            expires epoch ;
            }
   }

表示不设置缓存 .
(5). expires off

server {
        listen   90;
        server_name  localhost;
        
        location /czj {
            root  /home;
            expires off ;
            }
   }

采用默认的方式 , 也就是在Nginx端没有进行缓存的设置 , 但是浏览器端还是会有默认的缓存方式的.
(6). expires max

server {
        listen   90;
        server_name  localhost;
        
        location /czj {
            root  /home;
            expires off ;
            }
   } 

表示设置的最大的缓存过期时间 .

Nginx的反向代理缓存

在核心配置文件nginx.conf中添加一下配置

#proxy_cache_path 设置缓存保存的目录
#keys_zone设置共享内存以及占用的空间大小
#inactive超过此时间, 则缓存自动清理 
#use_temp_path 关闭临时目录
proxy_cache_path /usr/local/nginx/upsteam_cache keys_zone=mycache:5m max_size=10m inactive=1m use_temp_path=off;

server {
        listen   82;
        server_name  www.tomcatsCluster.com;
        
        #开启并且使用缓存
        proxy_cache mycache;
        #针对200304状态码的缓存设置
        proxy_cache_valid      200 304 8h
        
        location / {
            proxy_pass http://tomcatsCluster;
            }
   }        

要在server中开启缓存.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值