nginx怎么关闭favicon.ico、robots.txt日志记录


有朋友问我,如何关闭nginx中favicon.ico、robots.txt日志记录,不允许访问某些隐藏文件。

其实,有个favicon.ico挺好的,当网页放到任务栏上可以区分出自己的网站,对用户体验也不错。

另外就是robots.txt文件用好了,对屏蔽恶意收录是很有帮助的。

nginx日志最近发生大量访问favicon.ico无法找到的404错误日志,影响服务器性能,对于一个高并发的服务器每一个错误都会影响性能,所以需要关闭访问favicon.ico的日志记录功能。

操作方法:

# 把以下配置放到 server {} 块.
#关闭favicon.ico不存在时记录日志
location = /favicon.ico {
log_not_found off;
access_log off;
} www.jbxue.com
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# 不允许访问隐藏文件例如 .htaccess, .htpasswd, .DS_Store (Mac).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}

相关内容