How to route external domain to router website hosted in local virtualbox web server (Windows as host OS and CentOS 7 as guest OS)

There are test scenarios that requires a development site hosted in local web server accessible via live external domain. In this article, will show how to make a development site hosted in local virtualbox web server (Windows as host OS and CentOS 7 as guest OS). Note: make sure you have full administrator access to your router and the router's WAN IP is a public IP address.

Steps:

  1. Open and configure your Vagrantfile. Add the following lines:

          
    config.vm.network "forwarded_port", guest: 80, host: 2345
    config.vm.network "public_network"
          
        
  2. Do a vagrant up, open an SSH client and login as root.

  3. Execute on command prompt:

          
    ifconfig
          
        

    ... take note of the IP assigned by the router to our guest OS. In my case:

          
    enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.8  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::a00:27ff:fe89:1d21  prefixlen 64  scopeid 0x20
    ether 08:00:27:89:1d:21 txqueuelen 1000 (Ethernet) RX packets 1988 bytes 130047 (126.9 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 214 bytes 18448 (18.0 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

    ... the IP address assigned is 192.168.1.8.

  4. Configure the web server under your domain to listen the port 80 to 192.168.1.8. In my case, I am using Nginx as web server so the part that needs changing in the configuration:

          
    listen 192.168.2.8:80;
    server_name webfoobar.com www.webfoobar.com;
          
        
  5. Restart your web server:

          
    systemctl restart nginx.service
          
        
  6. Get the WAN IP of the router. Login to your router, go to "Device Info" and you will find the IP under "WAN Interfaces". Verify if the IP you've get is a public IP address. If the router is giving a private IP address (like starting with 100.XXX.XXX.XXX), it means there's another router on top of your router that holds the public IP address and that is the router that you need to configure for the next steps. So login to that router to get the public IP address.

  7. Configure the router to forward port 80 to your local computer's IP address. Go to "Advanced" then "NAT", under "Virtual Server", enter 80 on "WAN Port" and "LAN Open Port" fields and enter 192.168.1.8 on "LAN Ip Address" field. Then save it.

    Router forward port 80 to virtualbox IP address

  8. Login to your domain name provider or the service provider that resolve the DNS of your domain. In my case, I use Cloudflare. Under the "DNS" section, add or change the "A" record IP address to the public IP address that you got from your router. This will take time to update (sometimes only minutes or hours, it depends on your provider).

    Cloudflare webfoobar.com A record DNS settings

  9. Once the "A" record changes updated. Open a web browser, enter your domain name and you should see the website that is hosted in your virtualbox web server.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.