favicon.ico 文件是浏览器收藏网址时显示的图标,当使用浏览器访问页面时,浏览器
会自己主动发起请求获取页面的favicon.ico文件,但是当浏览器请求的favicon.ico文
件不存在时,服务器会记录404日志,而且浏览器也会显示404报错(F12查看浏览器请求情况)
解决方案:
1、不加favicon.ico图片:
服务器不记录访问日志:
location = /favicon.ico {
log_not_found off; #文件没发现事件不记录error_log
access_log off; #不记录access_log
}
2、将图标保存到指定目录访问,加favicon.ico图标:
#location ~ ^/favicon\.ico$ {
location = /favicon.ico {
root /data/nginx/html/pc/images;
}
示例:
在虚拟主机root /data/site14/资源目录加个favicon.ico小图片即可,浏览器Ctrl+F5,F12看结果,或者看访问日志
浏览器F5刷新结果:
{"@timestamp":"2021-03-07T11:03:43+08:00","host":"10.0.0.126","clientip":"10.0.0.1","size":0,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"www.magedu.org","uri":"/index.html","domain":"www.magedu.org","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36","status":"304"} #304是缓存
浏览器Ctrl+F5刷新结果:
{"@timestamp":"2021-03-07T11:03:57+08:00","host":"10.0.0.126","clientip":"10.0.0.1","size":24,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"www.magedu.org","uri":"/index.html","domain":"www.magedu.org","xff":"-","referer":"-","tcp_xff":"","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36","status":"200"}
{"@timestamp":"2021-03-07T11:03:57+08:00","host":"10.0.0.126","clientip":"10.0.0.1","size":571,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"www.magedu.org","uri":"/favicon.ico","domain":"www.magedu.org","xff":"-","referer":"http://www.magedu.org/","tcp_xff":"","http_user_agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36","status":"404"}
标签:10.0,浏览器,magedu,favicon,nginx,org,ico From: https://www.cnblogs.com/cnblogsfc/p/14517482.html