Re: getServerName returns 'localhost'
Hello Ivan, The headers x-forwarded-for, x-forwarded-host and x-forwarded-server are typically added by Apache Httpd mod_proxy (1). It seems that you use Apache Httpd mod_proxy in front of your Tomcat, both located on the same server (this is the reason why get localhost). Your solution may be to look at the "ProxyPreserveHost On" directive in Apache configuration (2). If you use It would look like : ProxyPreserveHost On ProxyPass /mypath http://localhost:8080/mypath Hope this helps, Cyrille -- Cyrille Le Clerc clecl...@xebia.fr http://blog.xebia.fr (1) see http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers (2) see http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypreservehost On Wed, Mar 3, 2010 at 5:09 PM, vgud wrote: > > I tried to log all request headers and notice three interesting headers: > > x-forwarded-for : 10.0.0.24 > x-forwarded-host : myRealDomain.com > x-forwarded-server : my.server.ip.address > > So, tomcat(or someone else) does some forwarding and attach those headers on > request? > > If so where and how it is configured? > > > n828cl wrote: > > > >> From: André Warnier [mailto:a...@ice-sa.com] > >> 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 or 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 name of localhost: > > serverName=usrv-caldarcr.na.uis.unisys.com > > serverPort=8080 > > > > It appears the OP has something else going on that's interfering with the > > target IP address. (Internal routing, perhaps?) > > > > - Chuck > > > > > > THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY > > 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: users-unsubscr...@tomcat.apache.org > > For additional commands, e-mail: users-h...@tomcat.apache.org > > > > > > > > -- > View this message in context: > http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27770177.html > Sent from the Tomcat - User mailing list archive at Nabble.com. > > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: getServerName returns 'localhost'
I tried to log all request headers and notice three interesting headers: x-forwarded-for : 10.0.0.24 x-forwarded-host : myRealDomain.com x-forwarded-server : my.server.ip.address So, tomcat(or someone else) does some forwarding and attach those headers on request? If so where and how it is configured? n828cl wrote: > >> From: André Warnier [mailto:a...@ice-sa.com] >> 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 or 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 name of localhost: > serverName=usrv-caldarcr.na.uis.unisys.com > serverPort=8080 > > It appears the OP has something else going on that's interfering with the > target IP address. (Internal routing, perhaps?) > > - Chuck > > > THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY > 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: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > > -- View this message in context: http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27770177.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: getServerName returns 'localhost'
> From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] > Subject: RE: getServerName returns 'localhost' > > 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 name > of localhost: > serverName=usrv-caldarcr.na.uis.unisys.com > serverPort=8080 The above works with 6.0.24 using both Jio and Nio connectors, with and without APR. Also works on 5.5.26 with the standard connector (haven't tried it with APR). - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 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: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: getServerName returns 'localhost'
> From: André Warnier [mailto:a...@ice-sa.com] > 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 or 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 name of localhost: serverName=usrv-caldarcr.na.uis.unisys.com serverPort=8080 It appears the OP has something else going on that's interfering with the target IP address. (Internal routing, perhaps?) - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 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: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
1. What, exactly, version of 5.5.x is used. 2. Is Tomcat running standalone, or is behind Apache HTTPD, IIS or other web server, or a load balancer 3. What connectors are configured in server.xml? What connectors (protocols) are mentioned in catalina.log at startup time. E.g.: 03.02.2010 12:10:01 org.apache.coyote.http11.Http11BaseProtocol init 4. Whether Tomcat-Native (tcnative-1.dll, tcnative-1.so) is used? 5. Operating system. 6. Are the clients using HTTP/1.1 or HTTP/1.0 Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
vgud wrote: Exactly. So, could it be configured somehow to make me able get correct domain? Ronald Klop wrote: Did you do something like this in server.xml? Maybe try this : >> >> www.example.com another.example.com athird.example.com >> (I mean specify the different domain names of your host explicitly as aliases) Does it work then ? (And sorry for the previous answer; I asked the right questions, but then gave the wrong answer anyway :-( ) - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: getServerName returns 'localhost'
> From: vgud [mailto:ivan.gudi...@yahoo.com] > Subject: Re: getServerName returns 'localhost' > > So, could it be configured somehow to make me able get > correct domain? Only if you added all possible domain names and variations thereof that get to that system's IP address(es). As Peter suggests, the proper approach is to use the HOST header in the request. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY 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: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
Peter Crowther wrote: On 3 March 2010 13:47, André Warnier wrote: André Warnier wrote: vgud wrote: My server responds to different domain names, and I want to know which one users use. [...] More precisely : getRemoteAddr public java.lang.String getRemoteAddr() Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR. Andre, you're answering the question of "which client sent this request?" The OP is asking a different question: "What hostname did the client send this request to?" I'd parse the host header in the request to find out, but that's just me! You are right, I am off-base here, apologies. String hostname = request.getHeader("Host") should work. But then, the question is, according to the OP, request.getServerName() returns "localhost", although that is very unlikely to have been used by the client in the Host header. However, the java API says : ServletRequest.getServerName 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 or tags with the corresponding names are set ? (A question for people who like to scan the code.. Christopher ?) - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
Exactly. So, could it be configured somehow to make me able get correct domain? Ronald Klop wrote: > > Did you do something like this in server.xml? > > > > > > And your client goes to www.example.com, but you getServerName() returns > "localhost" in stead of "www.example.com"? > > Ronald. > > Op woensdag, 3 maart 2010 14:19 schreef vgud : >> >> >> >> Users use tomcat directly. >> >> My server responds to different domain names, and I want to know which >> one >> users use. I try to get domain name by request.getServerName() but >> instead >> of domainName.com I get 'localhost'. >> >> >> awarnier wrote: >> > >> > vgud wrote: >> >> Gentlemen, >> >> >> >> I have the application which could be accessed from different domain >> >> addresses and I need to know from what domain request was sent. I try >> to >> >> get >> >> following from request: >> >> >> >> getRemoteHost: 127.0.0.1 >> >> getServerName: localhost >> >> >> >> I use tomcat 5.5 and I suppose i should configure something to get >> >> correct >> >> domain name. Can anyone help me?? Any help will be apreciated. >> >> >> > Are users accessing Tomcat directly ? or through an Apache front-end >> for >> > example ? >> > >> > Also, your question above is not very clear. Can you revisit your >> usage >> > of "from" above, and rephrase what you are trying to get exactly ? >> > Do you mean that your server responds to different domain names, and >> you >> > want to know which one users use ? >> > Or do you want to know from which (user-side) IP address they are >> > accesing your server ? >> > >> > >> > - >> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> > For additional commands, e-mail: users-h...@tomcat.apache.org >> > >> > >> > >> >> -- >> View this message in context: >> http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27768081.html >> Sent from the Tomcat - User mailing list archive at Nabble.com. >> >> >> - >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> >> >> >> > > > -- View this message in context: http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27768758.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
On 3 March 2010 13:47, André Warnier wrote: > André Warnier wrote: >> vgud wrote: >>> My server responds to different domain names, and I want to know which >>> one users use. [...] > More precisely : > > getRemoteAddr > > public java.lang.String getRemoteAddr() > > Returns the Internet Protocol (IP) address of the client or last proxy > that sent the request. For HTTP servlets, same as the value of the CGI > variable REMOTE_ADDR. Andre, you're answering the question of "which client sent this request?" The OP is asking a different question: "What hostname did the client send this request to?" I'd parse the host header in the request to find out, but that's just me! - Peter - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
Did you do something like this in server.xml? And your client goes to www.example.com, but you getServerName() returns "localhost" in stead of "www.example.com"? Ronald. Op woensdag, 3 maart 2010 14:19 schreef vgud : Users use tomcat directly. My server responds to different domain names, and I want to know which one users use. I try to get domain name by request.getServerName() but instead of domainName.com I get 'localhost'. awarnier wrote: > > vgud wrote: >> Gentlemen, >> >> I have the application which could be accessed from different domain >> addresses and I need to know from what domain request was sent. I try to >> get >> following from request: >> >> getRemoteHost: 127.0.0.1 >> getServerName: localhost >> >> I use tomcat 5.5 and I suppose i should configure something to get >> correct >> domain name. Can anyone help me?? Any help will be apreciated. >> > Are users accessing Tomcat directly ? or through an Apache front-end for > example ? > > Also, your question above is not very clear. Can you revisit your usage > of "from" above, and rephrase what you are trying to get exactly ? > Do you mean that your server responds to different domain names, and you > want to know which one users use ? > Or do you want to know from which (user-side) IP address they are > accesing your server ? > > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > > -- View this message in context: http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27768081.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
André Warnier wrote: vgud wrote: Users use tomcat directly. My server responds to different domain names, and I want to know which one users use. I try to get domain name by request.getServerName() but instead of domainName.com I get 'localhost'. Look up the java doc for HttpRequest. You should probably use remadr = request.getRemoteAddress() or something like that. That will give you the IP of the client, not your own IP. Then you should use a DNS lookup (I mean the equivalent Java function) to translate the remote IP into the corresponding remote name. request.getServerName() probably gives you the name of your own server (the one which is in the tag of your server.xml config file. More precisely : getRemoteAddr public java.lang.String getRemoteAddr() Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR. Returns: a String containing the IP address of the client that sent the request getRemoteHost public java.lang.String getRemoteHost() Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST. Returns: a String containing the fully qualified name of the client - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
vgud wrote: Users use tomcat directly. My server responds to different domain names, and I want to know which one users use. I try to get domain name by request.getServerName() but instead of domainName.com I get 'localhost'. Look up the java doc for HttpRequest. You should probably use remadr = request.getRemoteAddress() or something like that. That will give you the IP of the client, not your own IP. Then you should use a DNS lookup (I mean the equivalent Java function) to translate the remote IP into the corresponding remote name. request.getServerName() probably gives you the name of your own server (the one which is in the tag of your server.xml config file. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
Users use tomcat directly. My server responds to different domain names, and I want to know which one users use. I try to get domain name by request.getServerName() but instead of domainName.com I get 'localhost'. awarnier wrote: > > vgud wrote: >> Gentlemen, >> >> I have the application which could be accessed from different domain >> addresses and I need to know from what domain request was sent. I try to >> get >> following from request: >> >> getRemoteHost: 127.0.0.1 >> getServerName: localhost >> >> I use tomcat 5.5 and I suppose i should configure something to get >> correct >> domain name. Can anyone help me?? Any help will be apreciated. >> > Are users accessing Tomcat directly ? or through an Apache front-end for > example ? > > Also, your question above is not very clear. Can you revisit your usage > of "from" above, and rephrase what you are trying to get exactly ? > Do you mean that your server responds to different domain names, and you > want to know which one users use ? > Or do you want to know from which (user-side) IP address they are > accesing your server ? > > > - > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > > -- View this message in context: http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27768081.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: getServerName returns 'localhost'
vgud wrote: Gentlemen, I have the application which could be accessed from different domain addresses and I need to know from what domain request was sent. I try to get following from request: getRemoteHost: 127.0.0.1 getServerName: localhost I use tomcat 5.5 and I suppose i should configure something to get correct domain name. Can anyone help me?? Any help will be apreciated. Are users accessing Tomcat directly ? or through an Apache front-end for example ? Also, your question above is not very clear. Can you revisit your usage of "from" above, and rephrase what you are trying to get exactly ? Do you mean that your server responds to different domain names, and you want to know which one users use ? Or do you want to know from which (user-side) IP address they are accesing your server ? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
getServerName returns 'localhost'
Gentlemen, I have the application which could be accessed from different domain addresses and I need to know from what domain request was sent. I try to get following from request: getRemoteHost: 127.0.0.1 getServerName: localhost I use tomcat 5.5 and I suppose i should configure something to get correct domain name. Can anyone help me?? Any help will be apreciated. Best regards -- View this message in context: http://old.nabble.com/getServerName-returns-%27localhost%27-tp27767838p27767838.html Sent from the Tomcat - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org