页面有两个缓存。一个用于PC网络浏览器,另一个用于移动浏览器。
nginx可以做到这一点。 follow是nginx conf内容的一部分:
map $http_user_agent $device_type {
default 'pc';
~(iPhone|Android|IEMobile|Balckberry) 'mobile';
}
#fast cgi cache def
fastcgi_cache_path /data0/nginx-1.2.6/cache levels=1:2 keys_zone=nginx_webpy_cache:30m inactive=1d;
fastcgi_temp_path /data0/nginx-1.2.6/cache/temp;
fastcgi_cache_key "$request_method$scheme$host$request_uri$device_type$is_args$args";
#end
如您所见,我将$ device_type放入缓存密钥以用于两个缓存版本。
但我发现这个conf,我无法清除nginx缓存。如何清除这些拖动缓存版本?
非常感谢。
答案 0 :(得分:2)
我已经解决了这个问题。
以下是我的解决方案。
首先在nginx.conf的http范围中添加地图:
map $http_user_agent $device_type {
default 'pc';
~(iPhone|Android|IEMobile|Balckberry) 'mobile';
}
需要编辑fastcgi缓存密钥,如下所示:
#fast cgi cache def
fastcgi_cache_path /data0/nginx-1.2.6/cache levels=1:2 keys_zone=nginx_webpy_cache:30m inactive=1d;
fastcgi_temp_path /data0/nginx-1.2.6/cache/temp;
fastcgi_cache_key "$scheme$request_method$host/$device_type$request_uri$is_args$args";
#end
我将变量$ device_type放入缓存键。现在pc和手机有不同的缓存版本。
注意:如果你需要清除缓存,你应该清除拖曳版本。
如果您是中国人,请参阅以下文章: