nginx通过配置empty_gif解决请求favicon 404的问题
背景介绍
因为一些浏览器在访问网站时会默认去请求网站的favicon,但是我的网站(Tengine)上并没有这些icon图片,因此在访问日志里会出现大量的404错误,会触发一些没必要日志告警。
我们可以通过配置nginx empty_gif来给请求返回一个1x1,大小为43字节的空白图片来解决这个问题。这个给请求返回一个空白图片的做法经常用在网站统计等需求里。
empty_gif模块的官方链接地址:http://nginx.org/en/docs/http/ngx_http_empty_gif_module.html
配置
我统计我的日志里访问icon的请求,请求的目标文件总共有三个,所以对这些请求全部做返回空白图片处理。
nginx上添加如下配置:
location ~ ^/(apple-touch-icon.png|apple-touch-icon-precomposed.png|favicon.ico){
empty_gif;
}
测试
Wget
[root@thatsit vhosts]# cd /tmp/
[root@thatsit tmp]# wget http://www.thatsit.cc/favicon.ico
--2017-01-09 11:35:32-- http://www.thatsit.cc/favicon.ico
Resolving www.thatsit.cc... 10.10.10.101
Connecting to www.thatsit.cc|10.10.10.101|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43 [image/gif]
Saving to: “favicon.ico” 100%[=============================================================================================>] 43 --.-K/s in 0s 2017-01-09 11:35:32 (8.85 MB/s) - “favicon.ico” saved [43/43] [root@thatsit tmp]#
[root@thatsit tmp]# wget http://www.thatsit.cc/apple-touch-icon-precomposed.png
--2017-01-09 11:36:29-- http://www.thatsit.cc/apple-touch-icon-precomposed.png
Resolving www.thatsit.cc... 10.10.10.101
Connecting to www.thatsit.cc|10.10.10.101|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43 [image/gif]
Saving to: “apple-touch-icon-precomposed.png” 100%[=============================================================================================>] 43 --.-K/s in 0s 2017-01-09 11:36:29 (12.3 MB/s) - “apple-touch-icon-precomposed.png” saved [43/43] [root@thatsit tmp]#
[root@thatsit tmp]# wget http://www.thatsit.cc/apple-touch-icon.png
--2017-01-09 11:36:47-- http://www.thatsit.cc/apple-touch-icon.png
Resolving www.thatsit.cc... 10.10.10.101
Connecting to www.thatsit.cc|10.10.10.101|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 43 [image/gif]
Saving to: “apple-touch-icon.png” 100%[=============================================================================================>] 43 --.-K/s in 0s 2017-01-09 11:36:47 (12.3 MB/s) - “apple-touch-icon.png” saved [43/43] [root@thatsit tmp]# ll
total 24
-rw-r--r-- 1 root root 43 Sep 28 1970 apple-touch-icon.png
-rw-r--r-- 1 root root 43 Sep 28 1970 apple-touch-icon-precomposed.png
-rw-r--r-- 1 root root 43 Sep 28 1970 favicon.ico
[root@thatsit tmp]#
Curl
[root@thatsit tmp]# curl -XGET -I http://www.thatsit.cc/apple-touch-icon.png
HTTP/1.1 200 OK
Server: Tengine
Date: Mon, 09 Jan 2017 03:39:32 GMT
Content-Type: image/gif
Content-Length: 43
Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT
Connection: keep-alive [root@thatsit tmp]#
nginx通过配置empty_gif解决请求favicon 404的问题的更多相关文章
- nginx 本地配置(解决跨域问题)
前端做跨域本身就是扯淡的事情.后台人员不配合说什么都是白搭.索性整理了一下心得,(可以直接部署自配置)发不多说上代码: 1 #user nobody; 2 worker_processes 1; 3 ...
- nginx session 配置失效解决
nginx 反向代理后台web服务器session path导致的session 失效,特此总结下配置方法: 配置如下: location ^~ /2016tyjf_dev/djwechat { pr ...
- thinkphp nginx 上配置 并解决get获取到数据现象
server { listen 80; server_name XXXX.funova.net XXX.funova.com; root /opt/newgm; index index.php; lo ...
- Windows中Nginx配置nginx.conf不生效解决方法(路径映射)
Windows中Nginx配置nginx.conf不生效解决方法 今天在做Nginx项目的时候,要处理一个路径映射问题, location /evaluate/ { proxy_pass http:/ ...
- Nginx 高级配置--关于favicon.ico
Nginx 高级配置--关于favicon.ico 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.浏览器会默认帮咱们访问官网的图标 1>.浏览器访问网站"htt ...
- 解决Nginx+Tomcat下客户端https请求跳转成http的问题
Nginx上开启https, 后端使用Tomcat, 两者间走http协议, 但发现如果tomcat应用存在跳转时, 则客户端浏览器会出现400 Bad Request的错误, 通过抓包发现原因是 ...
- nginx中配置404错误页面的教程
什么是404页面如果网站出了问题,或者用户试图访问一个并不存在的页面时,此时服务器会返回代码为404的错误信息,此时对应页面就是404页面.404页面的默认内容和具体的服务器有关.如果后台用的是NGI ...
- NGINX: 配置跨域请求
说明: 内容全部来自 SegmentFault Developer Nginx 配置跨域请求 跨域请求失败, nginx 报错: 403 No 'Access-Control-Allow-Origin ...
- nginx+php-fpm配置后页面显示空白的解决方法以及用nginx和php-fpm解决“502 Bad Gateway”问题
For reference, I am attaching my location block for catching files with the .php extension: location ...
随机推荐
- TensorFlow Python2.7环境下的源码编译(一)环境准备
参考: https://blog.csdn.net/yhily2008/article/details/79967118 https://tensorflow.google.cn/install/in ...
- 基于python的scrapy框架爬取豆瓣电影及其可视化
1.Scrapy框架介绍 主要介绍,spiders,engine,scheduler,downloader,Item pipeline scrapy常见命令如下: 对应在scrapy文件中有,自己增加 ...
- ats编译中增加透明度 选项
在大多数情况下,如果环境支持透明度,则configure将自动启用它.对于其他环境,可能需要 配置configure 选项. --enable-posix-cap 这实现了POSIX功能,这是透明度所 ...
- openstack系列文章(二)
学习openstack的系列文章-keystone openstack 架构 Keystone 基本概念 Keystone 工作流程 Keystone Troubleshooting 1. open ...
- Windows下的ROUGE文本测评工具基本安装
需要的安装包: rouge1.5.5:https://pan.baidu.com/s/1B7-LYn1lZKC8f51yXxNK9w Strawberry Perl :http://strawberr ...
- Python处理PDF和Word文档常用的方法(二)
Python处理word时,需要安装和导入python-docx模块. 安装命令:pip install python-docx 导入命令:import docx 编码编写顺序:用docx.Docum ...
- trustbox文件破解
常见的破解方式,是要还原内容的二进制文件,删除加密壳部分的对应二进制数值,然后把剩下的内容保存下来,就实现了破解的任务. 淘宝破解链接:https://item.taobao.com/item.ht ...
- halt命令详解
基础命令学习目录首页 原文链接:https://www.jb51.net/LINUXjishu/57947.html 名称:halt 使用权限:系统管理者 halt 使用方式:halt [-n] [- ...
- NIO中的Buffer
public abstract class Buffer { // Invariants: mark <= position <= limit <= capacity private ...
- NABC for Teamproject
“教育是一个社会发展的支柱, 你和我能看到并理解这个博客, 教育功不可没. 高等教育的形式并不是一成不变的, 高等教育一直在演进.”邹欣老师在博客上如此写道.为了迎合信息化时代的特色,网络上的知识传 ...