The solution has two parts.
We need to allow your ubuntu server (guest) to be accessible via your browser in host.
We need to use shared folders so that ubuntu server (guest) can access those files.
Allow ubuntu server (guest) to be accessible via your browser in host
We are going to add new rule in the same NAT > Port forwarding rule in the settings seen here
The new rule is called
web. Host port is
8888 or anything that is larger than 1024. Guest port is
reboot in your terminal and try
http://localhost:8888 and you should see
Welcome to nginx!
assuming that in your host machine you matched 127.0.0.1 with localhost in your /etc/hosts file
Why can't we use
Because we use NAT setting in virtual box, we cannot translate anything less than 1024 to the guest port 80.
Why don't we use Bridged interface instead of NAT?
That is possible, but the disadvantage is you need to assign a static IP to the guest OS. It is also troublesome as it also requires you to be on a network.
My advice is that it is not worth the trouble. Simply using
http://localhost:8888 is good enough.
Setting up of shared folders
Log in back as root into your ubuntu guest
Type the following.
sudo apt-get update
sudo apt-get install dkms
sudo apt-get install virtualbox-guest-additions
sudo apt-get install build-essential linux-headers-$(uname -r)
sudo apt-get install virtualbox-ose-guest-x11
The purpose of this is to install something called Virtual Box Guest Additions
You need to install these packages inside the guest ubuntu OS.
Do use these same bash commands whenever you update your VirtualBox
Shutdown gracefully on the guest OS.
Now select settings on the guest OS and go to shared folders to add the folder you want to share from Mac OS X
Select automount and permanent to make your life easier.
Run the ubuntu server (guest) again. Log in as root.
Make sure that your www-data or whichever user you use to access the /var/virtual folders also belongs to the group
vboxsf. You cannot change the group that automounts the shared folders so you can only add users to the group.
The command to add
sudo adduser www-data vboxsf
Now create symlinks inside your /var/virtual to point to the appropriate folders and your setup of a webserver on an actual ubuntu server will work.