nginx缓存服务器加强版,nginx缓存加强版一个特性是,如果缓存


因为后端服务器经常发生503错误,所以服务不能保证,为了避免访问错误,可以在缓存服务器上做调整。一个特性是,如果缓存过期,但访问后端服务器又不能返回正常的内容,则使用缓存内容,保证服务质量。

Nginx里面可以增加一条这个:

proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504; 语法:  proxy_cache_use_stale error | timeout | invalid_header | updating | http_500 | http_502 | http_503 | http_504 | http_404 | off ...;

默认值:  

proxy_cache_use_stale off;

上下文:  http, server, location

如果后端服务器出现状况,nginx是可以使用过期的响应缓存的。这条指令就是定义何种条件下允许开启此机制。这条指令的参数与proxy_next_upstream指令的参数相同。

此外,updating参数允许nginx在正在更新缓存的情况下使用过期的缓存作为响应。这样做可以使更新缓存数据时,访问源服务器的次数最少。在植入新的缓存条目时,如果想使访问源服务器的次数最少,可以使用proxy_cache_lock指令。

相关内容