Redirect Apache virtual host to virtual machine

apache-2.2virtualization

I have a dedicated server running apache2 and I want to have several virtual machine (for different development environment). I already succeeded creating virtual machines using virtualbox.

My server has a static IP on the web, and I have a domain name.

I would like to make my subdomain via virtual hosts on apache redirecting to a virtual machine.
Is it possible ? How ?

I'm sorry if a question like this already exists, I don't know what keywords to search.

Thank you.

Best Answer

First setup NAT in virtualbox for the services you want to expose on your guest virtual machines.

Then in your apache configuration add the reverse proxy configuration.

Assuming your host's port 7890 translates to your guest's port 80 (or the relevant port for the service you are exposing) you could do the following.

<VirtualHost *:80>

    DocumentRoot /home/demo/public_html
    ServerName demo.example.com
    ErrorLog /var/log/apache2/demo-error.log
    CustomLog /var/log/apache2/demo.-access.log common

    ProxyRequests Off

    ProxyPass / http://127.0.0.1:7890
    ProxyPassReverse / http://127.0.0.1:7890

</VirtualHost>

You will need to enable the proxy and proxy_http apache modules (sudo a2enmod http http_proxy on Ubuntu).

Related Topic