I’ve recently added Varnish Cache to my server with cPanel installed. Varnish Caching is now installed server-wide. It acts as an invisible intermediary between clients and the server and delivers some major speed improvements, noticeably to Magento and Drupal websites.
The Varnish install script created by Shubham Mathur worked very well but it currently doesn’t consider additional IPs. Also, you’ll need something to amend the
$_SERVER['REMOTE_ADDR'] server variable to show the client’s IP address and not the server’s.
So to get Varnish working correctly across multiple IPs (required when you’re hosting TLS websites), here is my step-by-step guide:
- In Shell, run:
wget https://raw.githubusercontent.com/itseasy21/w3tools-varnish/master/install.sh -O ./varnish-install.sh
- Edit the Varnish configuration file located at /etc/varnish/default.vcl (see below)
- Install mod_remoteip either using EasyApache or collect the files from GitHub.
- Set Apache configuration to load mod_remoteip (I recommend adding it to pre_main_global.conf):
LoadModule remoteip_module modules/mod_remoteip.so
- Restart Apache and Varnish:
Here is the default varnish configuration file. I’d recommend copying the original (fully commented out) version before starting on this one.
You can probably see where your IP address will fit in and the names for these corresponding websites – change the regular expresssion to match more precisely. The last function vcl_error is completely optional.
I will update this post when Shubham amends his script. Have a look at its source code if you need to reset the default Apache port.