# 处理 favicon.ico错误
location = /favicon.ico {
alias /data/nginx/html/favicon.ico;
# 或者 root /data/nginx/html/;
#try_files $uri =204; # 直接返回空无法缓存
# empty_gif; #会强制返回空, 优先级太高,忽略网站下现在favicon.ico
# add_header Cache-Control "public, no-transform"; # public支持中间缓存(代理或CDN), | no-transform禁止中间代理或cdn压缩处理
expires max; # 最大缓存时间
access_log off; # 关闭日志
log_not_found off; # 不记录404错误
}
有效配置
location = /favicon.ico {
try_files $uri @empty_favicon;
access_log off;
log_not_found off;
expires 30d;
add_header Cache-Control "public";
}
location @empty_favicon {
empty_gif;
access_log off;
expires max;
}