0

A bit of background

I have a server with 3 IP addresses and 3 <Host> elements defined in the server.xml. I'm using IP-based virtual hosts.

I have enabled the Access Log Valve on each Host, logging to 3 different log files.

It's working correctly, and I can see the requests logged to the correct files depending on which IP I hit.

So far, so good.

Now I'm trying to diagnose a load balancer issue, so I need to see the IP that each incoming request is hitting.

My actual question

According to the docs if you include %A in the access log pattern it should record the "Local IP address".

eg. pattern="%h %A %l %u %t &quot;%r&quot; %s %b"

However, what I'm seeing is requests hitting any of the 3 virtual hosts all show the same Local IP (ie. all 3 logs files show the same Local IP for all requests)

I would expect to see a different Local IP in each log. I know for certain they have arrived on different IPs, because that's how IP-based virtual hosts works.

I wonder if %A is just outputting what Tomcat thinks it's IP address is, rather than it actually being the IP the request arrived on.

Is it possible to log the actual IP each request came in on? Is there a different attribute I should use?

Additional info

Server has 3 IPs and hosts file contains:

10.10.10.10   localhost
10.10.10.1    serverA
10.10.10.2    serverB

My server.xml contains:

<Connector port="80" protocol="HTTP/1.1"
        connectionTimeout="20000"
        redirectPort="443" server="Unknown"
        useIPVHosts="true" />
...
<engine>
    <Host name="localhost" appBase="C:\webapps" unpackWARs="true" autoDeploy="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %A %l %u %t &quot;%r&quot; %s %b"/>
    </Host>

    <Host name="serverA" appBase="D:\webapps\app01">
        <Context path="/myapp" docBase="D:\webapps\app01" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="serverA_access_log." suffix=".txt" pattern="%h %A %l %u %t &quot;%r&quot; %s %b"/>
    </Host>

    <Host name="serverB" appBase="D:\webapps\app02">
        <Context path="/myapp" docBase="D:\webapps\app02" />
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="serverB_access_log." suffix=".txt" pattern="%h %A %l %u %t &quot;%r&quot; %s %b"/>
    </Host>
</engine>
Andy Madge
  • 1,607
  • 2
  • 14
  • 14
  • Do the request URLs actually reference the IP addresses, or the hostnames (serverA, serverB)? If it's the latter, do those names resolve properly on the clients? – mustaccio Mar 17 '16 at 19:08
  • Request URL is like http://app.example.com/myapp This hits a load balancer which distributes traffic to a pool of IPs including 10.10.10.1 and 10.10.10.2 However the requests are going to the wrong virtual host and i can see them in the localhost log – Andy Madge Mar 17 '16 at 19:20

0 Answers0