mod_proxy / mod_proxy_ajp日志记录

时间:2013-01-13 12:43:41

标签: apache mod-proxy

我正在尝试将mod_proxy请求记录到单独的日志中,以识别其转发请求到哪个tomcat服务器。

VirtualHost配置:

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
<Proxy balancer://appcluster>
        BalancerMember ajp://192.168.1.1:8009/ route=tomcat01 keepalive=on retry=300 ttl=30
        BalancerMember ajp://192.168.1.2:8009/ route=tomcat01 keepalive=on retry=300 ttl=30
</Proxy>

NameVirtualHost *:80

<VirtualHost *:80>
 ServerName xyz.abc.com
 DocumentRoot /www
 ErrorLog logs/app_stg-error_log
 TransferLog logs/app_stg-access_log
 ProxyPass / balancer://appcluster/app_stg/ stickysession=JSESSIONID|jsessionid
 ProxyPassReverse / balancer://appcluster/app_stg/
</VirtualHost>

我想登录我的请求转发给哪个Balancer会员。

1 个答案:

答案 0 :(得分:1)

通过在LogFormat下面添加它来实现。

LogFormat "%h \"%{BALANCER_WORKER_NAME}e\" %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" custom

您可以将此格式添加到httpd.conf或虚拟主机中。

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
<Proxy balancer://appcluster>
        BalancerMember ajp://192.168.1.1:8009/ route=tomcat01 keepalive=on retry=300 ttl=30
        BalancerMember ajp://192.168.1.2:8009/ route=tomcat01 keepalive=on retry=300 ttl=30
</Proxy>

NameVirtualHost *:80

<VirtualHost *:80>
 ServerName xyz.abc.com
 DocumentRoot /www
 LogFormat "%h \"%{BALANCER_WORKER_NAME}e\" %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" custom
 ErrorLog logs/app_stg-error_log
 CustomLog logs/app_stg-access_log custom
 ProxyPass / balancer://appcluster/app_stg/ stickysession=JSESSIONID|jsessionid
 ProxyPassReverse / balancer://appcluster/app_stg/
</VirtualHost>

日志文件片段:

2xx.1xx.1xx.1xx "ajp://10.220.102.94:8009/" - [13/Jan/2013:08:36:54 -0500] "GET / HTTP/1.1" 400 - "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17"