首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Serve Googlebot清漆缓存

Serve Googlebot清漆缓存
EN

Stack Overflow用户
提问于 2015-03-02 18:45:00
回答 2查看 965关注 0票数 0

我目前正在用php5-fpm运行Nginx,我想在我的服务器设置中引入varnish,但我只想让varnish为Googlebot和Bingbot以及其他任何传递缓存的人提供缓存页面。

做这件事最好的方法是什么?运行varnish作为前端,还是运行nginx作为前端,并向varnish发送请求?此外,我会要求实际的代码请。

如有任何意见,我们将不胜感激

EN

回答 2

Stack Overflow用户

发布于 2015-03-03 23:43:27

基于用户代理,您可以识别机器人并让varnish缓存响应。有关更多信息,请参阅下面的清漆库https://github.com/varnish/varnish-devicedetect

但我想知道为什么你一开始就想把清漆放在里面,特别是为了只处理机器人。为什么不让nginx来处理缓存(如果这是一个实际的选择)。

票数 1
EN

Stack Overflow用户

发布于 2016-03-26 09:32:35

根据Marcel的回答,你可以只使用NGINX来处理Bot的响应缓存(不需要Varnish):

代码语言:javascript
复制
# 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_

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28807845

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档