2015-03-02 159 views
0

我目前正在用php5-fpm運行Nginx,我想向我的服務器設置中添加清漆,但我只想清漆將緩存頁面提供給Googlebot和Bingbot,並且任何人都通過緩存。服務Googlebot清漆緩存

這樣做的最好方法是什麼?運行清漆作爲前端或運行nginx作爲前端併發送請求清漆?另外我會要求實際的代碼。

任何評論都將根據您可以識別的機器人,讓清漆緩存響應用戶代理感激

+1

我正在投票結束這個問題作爲題外話,因爲SO不在這裏爲你寫代碼。 – Rob 2016-03-26 01:35:20

回答

1

。請參閱以下清漆庫以獲取更多信息https://github.com/varnish/varnish-devicedetect

但是我想知道爲什麼要在第一處放置清漆,特別是只處理機器人。爲什麼不讓nginx處理緩存(如果這是一個實際的選擇)。

0

擴展在馬塞爾的答案,你可以只使用NGINX處理的響應緩存機器人只(無需光油):

# Map any user agent not containing the word "bot" 
map $http_user_agent $isNotBot { 
    ~*bot ""; 
    default "IAmNotARobot"; 
} 

# Where to store cached files (adjust to your liking) 
proxy_cache_path /path/to/bot_cache 
    levels=1:2 
    keys_zone=bot_cache:10m 
    max_size=1g 
    inactive=30m 
    use_temp_path=off; 

server { 
    ... 
    location/{ 
    ... 
    # Which cache to use 
    fastcgi_cache bot_cache; 

    # key to use for the cached copies (adjust to your needs) 
    fastcgi_cache_key $host:$server_port:$request_uri; 

    # Bypass the cache for humans 
    fastcgi_cache_bypass $isNotBot; 

    # Don't store/cache copies of requests from humans 
    fastcgi_no_cache  $isNotBot; 

    # Uses stale cached responses for various upstream errors 
    # (ignored for humans) 
    fastcgi_cache_use_stale error timeout updating http_500; 

    # Disable getting gzipped files from back end 
    # (only cache un-gzipped responses) 
    fastcgi_set_header Accept-Encoding ""; 

    # upstream location 
    fastcgi_pass http://upstream; 
    ... 
    } 
    ... 
} 

取代fastcgi_proxy_scgi_uwsgi_這取決於代理模塊您正在使用。