我目前正在用php5-fpm运行Nginx,我想在我的服务器设置中引入varnish,但我只想让varnish为Googlebot和Bingbot以及其他任何传递缓存的人提供缓存页面。
做这件事最好的方法是什么?运行varnish作为前端,还是运行nginx作为前端,并向varnish发送请求?此外,我会要求实际的代码请。
如有任何意见,我们将不胜感激
发布于 2015-03-03 23:43:27
基于用户代理,您可以识别机器人并让varnish缓存响应。有关更多信息,请参阅下面的清漆库https://github.com/varnish/varnish-devicedetect
但我想知道为什么你一开始就想把清漆放在里面,特别是为了只处理机器人。为什么不让nginx来处理缓存(如果这是一个实际的选择)。
发布于 2016-03-26 09:32:35
根据Marcel的回答,你可以只使用NGINX来处理Bot的响应缓存(不需要Varnish):
# 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_。
https://stackoverflow.com/questions/28807845
复制相似问题