Quick Tip: Use Apache as a proxy server to access internal IPs from an external machine
Obviously running an Apache proxy to another server isn't something you will do lightly, and you may not do it at all for a production system; To use Apache as proxy on an unsecured server is inviting trouble, so make sure to do your security due diligence! But Just for testing, this can be a handy tip.
Fortunately it's a straightforward process Here are the steps to use Apache as proxy:
- Start by installing apache2. On Ubuntu, this is just a matter of calling the package manager:
sudo apt-get install apache2
- Enable the various modules needed to run an Apache proxy server. 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
- Access the Apache configuration and add the following content to the /etc/apache2/sites-available/000-default.conf file to read:
<VirtualHost *:*> ProxyPreserveHost On
Obviously, make sure to use your own target URLs. Also, set the Apache proxy to port 80 (or whatever port you choose -- in this case, 8081).
# 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> - After configuring and setting the required parameters, restart the apache2 service to finally use Apache as proxy:
service apache2 restart