我在haproxy后面运行nginx(在同一台服务器上运行)。 我已经configurationhaproxy在nginx上使用一个简单的html文件来validation服务已经启动,因为我没有/想在这个主机上有一个有效的“/”URL。 Nginx不支持OPTIONS请求types(据我所知),这是haproxy使用的默认值,所以我把它改成了GET。
由于我在nginx中打开了访问日志,因此我在访问日志中获取了所有这些正常运行时间轮询请求。 有没有办法,我可以configurationNginx忽略某些请求,并跳过日志logging?
这是haproxy的后端:
backend static_http option httpchk GET /test.html option redispatch balance roundrobin #fullconn 1000 server w1_static www1:81 check port 81 inter 2000
以下是我在nginx日志中看到的内容:
127.0.0.1 - - [24/Jul/2009:19:28:22 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-" 127.0.0.1 - - [24/Jul/2009:19:28:24 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-" 127.0.0.1 - - [24/Jul/2009:19:28:26 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-" 127.0.0.1 - - [24/Jul/2009:19:28:28 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-" 127.0.0.1 - - [24/Jul/2009:19:28:30 +0000] "GET /test.html HTTP/1.0" 200 12 "-" "-"
那么,你可以尝试有一个具体的位置指令。
就像是
location /test.html { access_log off; }
应该工作(未经testing)…
你现在可以做到这一点
http://nginx.org/en/docs/http/ngx_http_log_module.html
if参数(1.7.0)启用条件日志logging。 如果条件评估为“0”或空string,则不会logging请求
map $request_uri $loggable { / 0; /healthcheck.html 0; default 1; } server { ... access_log /var/log/nginx/access.log combined if=$loggable; }
没有内置的过滤function可以做你想做的事情。
有几个技巧,你可以尝试。 这些都会导致您不感兴趣的数据被logging到不同的文件中,您可以根据自己的需要经常在外部对其进行加载(请记住HUP nginx)。
如果haproxy是请求/test.html的唯一东西,那么每个位置块可以有不同的访问日志(不幸的是不是位于块的内部的if块)。
如果其他节点请求/test.html,但来自127.0.0.1的所有请求都是haproxy,则可以创build基于$ remote_addr的映射,将127.0.0.1转换为access_log.junk,其他所有内容都转换为access_log。 在访问日志语句的名称中使用mapvariables
如果没有,你有源,所以你需要什么破解。