Nginx作为代理服务_场景配置补充说明

Nginx作为代理服务_场景配置补充说明

1、如何清理指定缓存?

(1)方式一:rm -rf 缓存目录内容

(2)方式二:第三方扩展模块ngx_cache_purge

 

2、如何让部分页面不缓存?

(1)proxy_no_cache配置语法

Syntax:

proxy_no_cache string ...;

Default:

Context:

httpserverlocation

语法解释:

Defines conditions under which the response will not be saved to a cache. If at least one value of the string parameters is not empty and is not equal to “0” then the response will not be saved:

proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;

proxy_no_cache $http_pragma    $http_authorization;

(2)proxy_no_cache配置演示

Nginx作为代理服务_场景配置补充说明

配置详解:

#表示客户端请求地址等于113.97.34.37,就把$cookie_nocache变量值设置为1;

if ($remote_addr = 113.97.34.37) {

        set $cookie_nocache 1;

}

#表示配置了缓存

proxy_cache one;

#表示设置是否需要缓存,如果$cookie_nocache不等于空或者不等于“0”表示不设置nginx缓存,否则表示设置缓存

proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;

(3)查询本机ip地址

Nginx作为代理服务_场景配置补充说明

(4)验证proxy_no_cache配置是否生效

       多次访问http://193.112.108.135/,轮询Round Robin返回结果

Nginx作为代理服务_场景配置补充说明

Nginx作为代理服务_场景配置补充说明

Nginx作为代理服务_场景配置补充说明