1. Create a new site file
vim /etc/apache2/sites-available/www.example.com.conf
<VirtualHost *:80>
ServerName www.example.com
ServerSignature Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
ProxyRequests off
ProxyPass / http://x.x.x.x/
ProxyPassReverse / http://x.x.x.x/
</VirtualHost>
2. Enable the proxy modules
a2enmod proxy_http
systemctl restart apache2.service
3. Enable the new site
a2ensite www.example.com.conf
systemctl reload apache2.service
To have the true remote IP address of a page request, enable XFF to forward the remote IP to the backend (non-public facing) web server.
In your vhost config:
RemoteIPHeader X-Forwarded-For
Enable the remoteip
module.
a2enmod remoteip
In my case, I'm using PHP to write the client's IP address on one of the pages.
<?php echo $_SERVER['HTTP_X_FORWARDED_FOR'];?>
Instead of:
<?php echo $_SERVER['REMOTE_ADDR'];?>
REMOTE_ADDR
would be used on a public facing server that talks directly to the client.