Tomcat通过Haproxy获取访问的源IP
1.Haproxy端配置# more haproxy.cfg
# this config needs haproxy-1.1.28 or haproxy-1.2.1
global
log 127.0.0.1 local3
log 127.0.0.1 local1 notice
maxconn 1000
pidfile /data/haproxy/logs/haproxy.pid
daemon
nbproc 2
defaults
log global
mode http
option httplog
option dontlognull
retries 3
maxconn 2000
contimeout 600000
clitimeout 600000
srvtimeout 600000
option redispatch
option forwardfor
2.Tomcat端配置
# more server.xml
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.You may obtain a copy of the License at
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="
logs" prefix="localhost_access_log." suffix=".txt" pattern='%h %l %T %t "%r" %s
%b "%{Referer}i" "%{User-Agent}i" %{X-Forwarded-For}i'resolveHosts="false" />
2.验证效果
192.168.1.20 - 0.002 "GET /asf-logo.png HTTP/1.1" 304 - "http://192.168.1.20/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729;.NET CLR 3.0.30729; Media Center PC 6.0; SE 2.X MetaSr 1.0)" 192.168.1.9
192.168.1.20 - 0.005 "GET /bg-middle.png HTTP/1.1" 304 - "http://192.168.1.20/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media CenterPC 6.0; SE 2.X MetaSr 1.0)" -
192.168.1.20 - 0.011 "GET /bg-button.png HTTP/1.1" 304 - "http://192.168.1.20/" "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media CenterPC 6.0; SE 2.X MetaSr 1.0)" 192.168.1.9
页:
[1]