How do I serve a website from a virtual machine on virtualbox?
Solution 1
As CelticWarrior mentions, Easiest way is to change the Network configuration of the VM in your Hypervisor (either Vbox or VMware or KVM). Whichever Hypervisor you are using, configure the Network connection to sit in the same network as the HOST, instead of Natted.
If you still want to NAT on your VM, or do not have the option to change it; you can configure IPtables to perform a Port-Forward to the VM's IP and port number. Using something like the following link:
Solution 2
In VirtualBox you can use as network adapter a network bridge. Than your virtual ubuntu should get an IP address from your intern network. (It is easier to give the IP manually so it is everytime the same IP) Than you have to forward port 80 in your router to port 80 of the network IP from your virtual ubuntu. If you than browse to your extern IP (you see it in your router) than you shall see your webside. You dont need Apache in your host if you want to build a virtual server.
Related videos on Youtube
Comments
-
Lasserh over 1 year
I have an Ubuntu 16.04 host that has an Ubuntu 16.04 guest running on virtualbox. I have apache2 set up on both machines, they serve each their own websites. I can reach the website on the guest from the host - that works fine - but when I try to reach the website on the guest from any other computer I get an error that the host could not be reached.
I'm using a bridge to connect the guest to the network. The guest can ping all other machines on the same network and also 8.8.8.8. All other machines on the network can ping the guest. I've added the guest machine's ip in the host machine's /etc/hosts.
What do I need to do to be able to reach the website on the guest machine from the internet?
-
Admin about 7 yearsIf you can access the website from any machine in the same network other than the host, then it's a network configuration issue. If only from the host then you probably need to change the network settings in the VM.
-
Lasserh about 7 yearsI've edited the question to clarify
-
-
Delorean about 7 yearsThis is correct, and how I've set up my VM's (bridged).
-
Lasserh about 7 yearsThe Web server on the host works fine. My router forwards port 80. What I need to do is to serve a different website on the guest vm.