nginx报错 open() “/usr/local/nginx/html/favicon.ico“ failed
一、产生原因
nginx核心配置文件:
server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.html index.htm;}#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}
}
当浏览器访问ip:80时,会访问html目录下的index.html,同时浏览器会自动访问该目录下favicon.ico文件,作为浏览的图标,如果在这个目录没有的话就会报这个错。
二、解决方法
• 直接忽略,不影响使用
• 在html目录下创建个文件favicon.ico
• 在配置文件中加入如下配置(推荐):
# set site faviconlocation /favicon.ico {log_not_found off;access_log off;}以上配置说明:location = /favicon.ico 表示当访问/favicon.ico时,log_not_found off 关闭错误日志access_log off 不记录在access.log
三、缓存相关
浏览器第一次访问的时候,才会报这个错误,然后后面不会报错,是因为浏览器缓存的原因,清空缓存后会立即再次报错;另外这个错误时访问静态文件时,浏览器自动访问的,如果nginx作为反向代理,那么就饿灭有该问题了。