Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Question on Virtual Box 4.1.8
So, i have Ubuntu 10.10 as host machine and Windows Xp as guest machine. On host machine there is tomcat with web app running on port 8888. When i am in guest machine i type in browser:
http://10.0.2.2:8888/Something.html and it works.
But my Something.html has links to javascript like src="http://localhost:8888/webApp/someScript.js and they obviously aren't working(because of "localhost" part).
The other problem is that i don't want to use relative path now, only absolute. Also i don't want to change localhost to Host Ip in my links
Maybe there is some solution, like port forwarding or network config of Virtual box, that i can type in my guest browser http://localhost:8888/Something.html

Thanks for any clues.

share|improve this question
    
I have no idea if Windows uses 'localhost' for anything internally (I don't think it does - but could be wrong). If it doesn't what you can do is to map 'localhost' to 10.0.2.2 (instead of the typical 127.0.0.1) on your Windows guest. Edit %SystemRoot%\system32\drivers\etc\hosts and add/modify 10.0.2.2 localhost. (On Linux this would definitely be a bad idea, but you might get away with it on Windows). –  cyberx86 Mar 24 '12 at 12:26
    
Already tried. It doesn't work. Windows Xp always maps localhost to 127.0.0.1. –  IgorDiy Mar 24 '12 at 12:32

2 Answers 2

up vote 4 down vote accepted

Your real problem is that you want to do things that doesn't make sense for any kind of web app that should serve anything outside it's machine: You need links that work without tricks on the client machine, either with relative paths where applicable or non-local hostnames.

Of course there is a workaround:

Simply install Putty on Windows and use it to create a port forwarding from port 8888 on your machine to port 8888 on 10.0.2.2. You will find lots of links with Google that explains how this is done in Putty.

Afterwards, you can simply connect to localhost:8888 and stuff should work.

share|improve this answer

If you manually add a hostname for the host in /etc/hosts (on the host) and in %systemroot%\system32\drivers\etc\hosts (on the guest), you can use that name in your code. And since both machine can resolve it it should work. As SvenW mentioned that's not the way one is supposed to solve it but should be fine for testing purposes.

Example of the hosts entry:

10.0.2.2 webapphoster

...and then you can call the js:

src="http://webapphoster:8888/webApp/someScript.js"
share|improve this answer

Your Answer

 
discard

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.