2015-03-02 114 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_这取决于代理模块您正在使用。