Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

localhost - 从VirtualBox虚拟机寻址localhost(Addressing localhost from a VirtualBox virtual machine)

I have a local test/development server (HTTP, of course), listening to port 8000.

(我有一个本地测试/开发服务器(当然是HTTP),监听端口8000。)

I'm working on Linux, so to test the page on Internet Explorer 6, 7, 8, etc. I run a virtual machine using VirtualBox;

(我正在使用Linux,所以要在Internet Explorer 6,7,8等上测试页面。我使用VirtualBox运行虚拟机;)

I also need to see how it look on Firefox in a windows environment (fonts for instance are different).

(我还需要看看它在Windows环境中的外观如何(例如字体不同)。)

In my real machine, I open the website simply using the URL http://localhost:8000 , how do I address this localhost from the virtual machine?

(在我的真机中,我只是使用URL http://localhost:8000打开网站,如何从虚拟机中寻址此本地主机?)

Right now my workaround is to use the IP address.

(现在我的解决方法是使用IP地址。)

Any better ideas?

(有更好的想法吗?)

  ask by hasen translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Googling turned this up: http://data.agaric.com/localhost-from-virtualbox-xp-install-ubuntu

(谷歌搜索转此: http//data.agaric.com/localhost-from-virtualbox-xp-install-ubuntu)

It suggests using IP: http://10.0.2.2 , and it worked for me.

(它建议使用IP: http://10.0.2.2http://10.0.2.2 ,它对我http://10.0.2.2 。)

So, I edited the hosts file, C:\windows\system32\drivers\etc\hosts , and added this entry:

(所以,我编辑了hosts文件, C:\windows\system32\drivers\etc\hosts ,并添加了这个条目:)

10.0.2.2   outer

If you're testing on IE8, remember to put http:// in the address bar.

(如果您正在测试IE8,请记得在地址栏中输入http:// 。)

Just putting the ip directly will not work.

(只是直接放入IP将无法正常工作。)

For example:

(例如:)

http://10.0.2.2:3000/

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...