Nginx – VirtualBox and Windows 10: can’t connect to a server hosted on VirtualBox

nginxvirtual-machinesvirtualbox

Not a duplicate – I searched a lot and tried to use suggestions from many articles, including answers to this question: VirtualBox: How to set up networking so both host and guest can access internet and talk to each other and this article. But in the end I get "ERR_CONNECTION_TIMED_OUT".

I have Windows 10, latest VirtualBox with CentOS 7 on it. I installed nginx and configured server to listen to port 8080, server name localhost. I want to connect to the nginx server from host (windows).

I tried NAT, Bridged network, Host-only e.t.c. Same result. Tried to set up static IP on CentOS. Tried to allow all input/output network requests from/to IPs: 192.168.56.1 (according to VirtualBox, this is host local IP) and 192.168.56.110 in Windows Firewall.

I can ping/check with curl that my nginx server is working fine. So this is not the case.

Best Answer

Assuming you are trying to access the VM from Win10.

  1. Configure network Right-click the VM icon in the Oracle VM VirtualBox Manager window which you want to access from the host and click settings on the menu. Go to the Network tab and set up the VM network to NAT Network. enter image description here

  2. Configure forwarding Click File->Preferences on the Oracle VM VirtualBox Manager window, and then click the Network tab. You will see a network listed(if not, just click the Add icon to add one), click the network name and then click the edit icon. enter image description here

On the NAT Networks Details windows, click the Port Forwarding. enter image description here

Click Add icon to add a port forwarding rule, like enter image description here

and then click OK OK OK to save the rule. Please note, the Guest IP is your CentOS VM IP.

  1. Set up VM. Now back to your CentOS VM, set the ipv4.method to auto(since you've changed the default IP configuration before) and then restart the network service. enter image description here
  2. Add firewall rule. You should add a rule for port 8080 by

    firewall-cmd --add-port=8080/tcp --permanent

Then you may access port 8080 on VM form you Win 10 host. enter image description here