2013-05-13 48 views
0

頁面有兩個緩存。一個用於PC網頁瀏覽器,另一個用於移動瀏覽器。如何清除不同用戶代理的nginx緩存

nginx可以做到這一點完美。如下是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緩存。如何清除這些拖放緩存版本?

非常感謝。

回答

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和手機有不同的緩存版本。

注意:如果你需要清除緩存,你應該清除拖拽的版本。

,如果你是中國人,請參閱遵循文章:

nginx cache with different user agent