阿里云1000元通用代金券点此领取
最近公司购买了阿里云的SLB服务,健康检测使用的是http和https协议,直接访问web。
后端的80端口是nginx。阿里云会按设置的健康检测时间使用get方法,去访问域名下的检查路径,判断web是否存活。
当前检查时间设置的是两秒,但是nginx的access.log,看到有大量ip为100.x的阿里云内网ip不断访问,大概一秒有个七八次,产生了很多无用的日志
现在就需要过滤掉这些日志,nginx有一个第三方模块ngx_log_if,下载地址:https://github.com/cfsego/ngx_log_if/,这个模块可以不记录指定的信息的日志,下载好后解压,并重新编译nginx,加入这个第三方模块
./configure --add-module=/usr/local/src/ngx_log_if-master --prefix=/usr/local/nginx/ --with-openssl=/usr/local/src/openssl-1.0.2j/ --with-pcre=/usr/local/src/pcre-8.38 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module
然后在nginx.conf进行编辑,过滤掉不需要的日志信息
server{
listen 80;
server_name xxx.xxx.com;
index index.jsp index.htm index.html;
location / {
proxy_store off;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_pass http://localhost:9999;
access_log_bypass_if ($uri = '/pic/debug.jsp'); #这里就写需要过滤路径
}
}
然后重启nginx,就不会有大量的健康检查日志出现了。但是访问这个页面的其他日志也被过滤掉了,所以建议使用一个专门的静态文件进行健康检查。