Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am developing a web application on my desktop and it is running on port 80. I am able to access the application from my laptop connected to the LAN by entering my desktop's LAN IP address Now, my application sends a redirect after login, but my laptop assumes the final address is localhost/login. If I manually type in the IP address and URI for any page, it shows that I am logged in, so it works as expected. So, why does the redirect assume localhost?

Both of my machines are linux-based. The laptop being Chrome OS. I am running nginx which proxies non-static file requests to jetty on port 8080.

$ cat /etc/hosts locahost desktop
$ hostname

The redirect is sent from Jetty, with a HttpServletResponse.sendRedirect()


Laptop: Request
Desktop: Respond with redirect to /index
Laptop: Redirect request to http://localhost/index

Requesting http://desktop/login doesn't work.
share|improve this question
Check your hosts file ? – harrymc Jan 16 '11 at 17:57
How did you implement the redirect? Let us see config code, if possible. – Tobias Plutat Jan 16 '11 at 18:20
@Tobias: What do you want to know? I don't know what else to provide. – Jeremy Heiler Jan 16 '11 at 18:21
Sorry, hitting Enter for a linebreak: Not such a good idea on StackExchange. Edited it in. – Tobias Plutat Jan 16 '11 at 18:22
I added some information. – Jeremy Heiler Jan 16 '11 at 18:38
up vote 1 down vote accepted

There is... nothing anywhere that implicitly redirects to localhost. Something within the framework or application is explicitly doing it.

share|improve this answer

When connecting to any local interface address, the connection is done from (the local loopback address). This doesn't require a redirect. The name of this address is localhost, as you will find in /etc/hosts. Many applications will check other local interfaces for a name and use that in preference to localhost.

share|improve this answer
My application requires a redirect. I don't understand why, when my server sends a redirect response, the redirect contains localhost instead of the IP address that made the initial request. – Jeremy Heiler Jan 16 '11 at 18:19
The incoming connection from localhost likely arrives on the localhost address. If you don't rewrite the address in your redirect, it will be redirected on the same address. Redirect to instead of just /login. – BillThor Jan 16 '11 at 18:24
That doesn't really solve my problem, though. This application will eventually be deployed elsewhere, so I can't hardcode an IP address in the redirect. – Jeremy Heiler Jan 16 '11 at 18:28
Use the hostname from the incoming request. This will work wherever you deploy, and will handle a deployment with multiple name. – BillThor Jan 17 '11 at 1:24

Jetty is prefacing every relative URL with its root domain (in Apache, it's called "Server Name", don't know about Jetty), I suppose: Hence the "localhost". So you need to replace the "localhost" with something that makes sense for both computerss:

You could make a domain like "" your webroot in Jetty and define it as your webroot and add it to the laptop's hosts file.

share|improve this answer
Thanks Tobias, I think you have tipped me in the right direction. I turned off the proxy through nginx and things are working correctly by directly making requests to jetty. Now I'll just need to configure the proxy correctly. Thanks again. – Jeremy Heiler Jan 16 '11 at 19:49
@Jeremy: This indicates that Jetty or the app isn't correctly accommodating the X-Forwarded-For header generated by the proxy. – Ignacio Vazquez-Abrams Jan 16 '11 at 19:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.