大网数据广告活动
服务器运维问答

Preventing Apache from logging HAProxy requests

· 52CE 我爱测

I have two HAProxy VMs and two Apache VMs (vagrant machines) as follows. 192.168.50.11 HAPROXY VM1 192.168.50.12 HAPROXY VM2 192.168.50.21 APACHE VM1 192.168.50.22 APACHE VM2 The problem I'm having is the Apache access.log file i…

问题原文

原帖链接 · BentCoder · CC BY-SA 3.0

I have two HAProxy VMs and two Apache VMs (vagrant machines) as follows.

192.168.50.11 HAPROXY VM1
192.168.50.12 HAPROXY VM2
192.168.50.21 APACHE VM1
192.168.50.22 APACHE VM2

The problem I'm having is the Apache access.log file is growing every second, because both HAProxy servers are pinging both Apache servers even when there is no request from any client. I need to stop recording unnecessary logs like shown below. I have the keepalived service running on both HAProxy servers.

$sudo tail -f /var/log/apache2/access.log

192.168.50.11 - - [09/Jul/2016:12:46:49 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.11 - - [09/Jul/2016:12:46:51 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.12 - - [09/Jul/2016:12:46:51 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.11 - - [09/Jul/2016:12:46:51 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.11 - - [09/Jul/2016:12:46:53 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.12 - - [09/Jul/2016:12:46:53 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.11 - - [09/Jul/2016:12:46:53 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.11 - - [09/Jul/2016:12:46:55 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.12 - - [09/Jul/2016:12:46:55 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
192.168.50.11 - - [09/Jul/2016:12:46:55 +0000] "OPTIONS / HTTP/1.0" 200 180 "-" "-"
.......
.......

These are not actual requests from anyone.

haproxy.cfg

global
    log /dev/log local0
    log 127.0.0.1 local1 notice
    user haproxy
    group haproxy
    maxconn 2000
    daemon

defaults
    log global
    mode http
    option httplog
    option dontlognull
    retries 3
    timeout connect 5000
    timeout client 50000
    timeout server 50000

frontend http-in
    bind 192.168.50.10:80
    default_backend webservers

backend webservers
    balance roundrobin
    stats enable
    stats auth admin:admin
    stats uri /haproxy?stats
    option httpchk
    option forwardfor
    option http-server-close
    server webserver1 192.168.50.21:80 check
    server webserver2 192.168.50.22:80 check

已采纳解答

原帖链接 · HBruijn · CC BY-SA 3.0

The trick is to set an environment flag for certain requests with the SetEnvIf directive and then instruct Apache to not log requests matching that:

SetEnvIf Request_URI \.gif do-not-log-this-request
SetEnvIf Remote_Addr "192\.168\.50\.11" do-not-log-this-request
SetEnvIf Request_Method OPTIONS do-not-log-this-request

CustomLog logs/access_log common env=!do-not-log-this-request 

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。