tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vgud <>
Subject RE: getServerName returns 'localhost'
Date Wed, 03 Mar 2010 16:09:53 GMT

I tried to log all request headers and notice three interesting headers:

x-forwarded-for :
x-forwarded-host :
x-forwarded-server : my.server.ip.address

So, tomcat(or someone else) does some forwarding and attach those headers on

If so where and how it is configured?

n828cl wrote:
>> From: André Warnier []
>> Subject: Re: getServerName returns 'localhost'
>> public java.lang.String getServerName()
>>      Returns the host name of the server to which the request was sent.
>> It is the value of the part before ":" in the Host header value, if
>> any, or the resolved server name, or the server IP address.
>>      Returns:
>>          a String containing the name of the server
>> That does not seem to work in his case.
>> Does it only work when the <Host> or <Alias> tags with the
>> corresponding names are set ?
> The code shows that the HOST header is being used by getServerName(). 
> Testing with the RequestDumperFilter enabled in examples/WEB-INF/web.xml
> shows that it works as documented; here's a portion of the output from
> Tomcat running on my desktop with the default <Host> name of localhost:
>         serverPort=8080
> It appears the OP has something else going on that's interfering with the
> target IP address.  (Internal routing, perhaps?)
>  - Chuck
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

View this message in context:
Sent from the Tomcat - User mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message