Quick Tip: Use Apache as a proxy server to access internal IPs from an external machine

Sometimes, when you’re using a cloud server, you find yourself in a situation where you don’t have a GUI, but you still want to access a web server running on a local IP address. For example, if you install MCP using the Model Designer, what you get back will be an instance that includes DriveTrain running on a local IP address.  To solve this problem, we can use Apache as a proxy server to access that local IP address via an external IP address to that VM.

Obviously this isn’t something you will do lightly, and you may not do it at all for a production system; make sure to do your security due diligence! But Just for testing, this can be a handy tip.

Fortunately it’s a straightforward process with just a few steps:

  1. Install apache2. On Ubuntu, this is just a matter of calling the package manager:
    sudo apt-get install apache2
  2. Enable the various modules needed. You can do that with the a2enmod tool:
    a2enmod proxy
    a2enmod proxy_http
    a2enmod proxy_ajp
    a2enmod rewrite
    a2enmod deflate
    a2enmod headers
    a2enmod proxy_balancer
    a2enmod proxy_connect
    a2enmod proxy_html
  3. Configure Apache by editing the /etc/apache2/sites-available/000-default.conf file to read:
    <VirtualHost *:*>
        ProxyPreserveHost On
    
        # Servers to proxy the connection, or;
        # List of application servers:
        # Usage:
        # ProxyPass / http://[IP Addr.]:[port]/
        # ProxyPassReverse / http://[IP Addr.]:[port]/
    
        # Example: 
        ProxyPass / http://10.10.0.15:8081/
        ProxyPassReverse / http://10.10.0.15:8081/
    
        ServerName localhost
    </VirtualHost>

    Obviously, make sure to use your own target URLs.

  4. Restart the apache2 service:
    service apache2 restart

At this point you can access the internal IP address (or whatever address you chose) from the main URL served by Apache.  

LIVE DEMO
Create True Multi-Cloud Applications with Istio
REGISTER
TECHNICAL TRAINING
OS200
OpenStack Bootcamp II
LEARN MORE

Nick Chase (@nickchase on Twitter)

Nick Chase is Head of Technical and Marketing Content for Mirantis. He is a member of the Kubernetes 1.15 release team, and the author of multiple books on technical topics, including Understanding OPNFV and Machine Learning for Mere Mortals.

LIVE DEMO
Create True Multi-Cloud Applications with Istio
REGISTER