jaquar c
jaquar c

Reputation: 31

VirtualBox: How to access virtual host on VM from host?

How to access from the host the Apache virtual domain created on virtual machine.

Settings of the VM on VirtualBox:

From the browser on the host machine I can access VM's localhost as http://192.168.205.10/index.html How can I access VM's example.com?

On the host's /etc/hosts I have added line for example.com

127.0.0.1   localhost
127.0.0.2   tmp.loc
127.0.0.3   temp.loc
192.168.205.10  example.com

When I try http://example.com/mj.html I get the 404 Not Found page from Apache/2.2.22 (Ubuntu) Server at example.com Port 80

On the virtual machine I can access page with the Lynx

lynx http://example.com/mj.html

This is noted in the /home/vagrant/www/example.com/logs/example.com-access.log file as

127.0.0.1 - - [03/Apr/2016:15:53:49 +0000] "GET /mj.html HTTP/1.0" 200 344 "-" "Lynx/2.8.8dev.9 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/2.12.14"

But when I try to access example.com from the host there are no logs neither in access.log nor /home/vagrant/www/example.com/logs/example.com-error.log

There are no logs in the host's Server files /opt/lampp/logs/access_log and /opt/lampp/logs/error_log

Upvotes: 2

Views: 4030

Answers (2)

mathematicalman
mathematicalman

Reputation: 306

On Ubuntu /etc/hosts:

127.0.0.1       localhost
127.0.2.2       example.com

On Windows (VBox) C:\Windows\System32\drivers\etc\hosts:

10.0.2.2 localhost
10.0.2.2 example.com

Then just reboot your VBox Windows and type in browser (on Windows): http://example.com/

Upvotes: 1

soukaina
soukaina

Reputation: 49

I have the same issue, I've been trying to access my drupal project from my virtualbox vm but it is not working. One of the solutions I found on the Internet is using the outer keyword in your hosts file in the VM.

The following works fine for me:

  1. In your host machine (let's say a ubuntu) type: ifconfig, and get the inet address of wlan0 (example: 192.168.1.15)
  2. Add this address to the host file in your virtualobox machine and use the outer keyword

    [192.168.1.15 outer]
    

Now you can access your localhost from your virtualbox browser by typing the address of your wlan0 (ex: 192.168.1.15).

  • If you need to access a specific port on your host add the port number to the address example 192.168.1.15:8001

Upvotes: 0

Related Questions