This article is intended for Linux server administrators who want to install or remove Varnish Cache. If your server is hosted with and managed by Maxer, please contact our support team and we can do this for you. Do not attempt these steps if you are unsure.

Note for cPanel servers:
cPanel now includes NGINX caching support directly in WHM. If you want caching in front of Apache, we recommend using the built-in NGINX option instead of installing Varnish manually. More details: WHM » Home » Software » NGINX Manager.


What is Varnish Cache?

Varnish Cache is an advanced, open-source web application accelerator (reverse proxy) that can significantly improve website performance by caching dynamic content in memory. It is often used in front of Apache or NGINX to handle high traffic loads.


Step 1: Install Varnish Cache on a non-cPanel server

On RHEL/AlmaLinux/Rocky (systemd-based):

dnf install -y epel-release
curl -s https://packagecloud.io/install/repositories/varnishcache/varnish70/script.rpm.sh | bash
dnf install -y varnish

On Debian/Ubuntu:

apt update
apt install apt-transport-https curl gnupg lsb-release
curl -s https://packagecloud.io/install/repositories/varnishcache/varnish70/script.deb.sh | bash
apt install varnish

Replace varnish70 with the appropriate LTS or stable release. See the official installation guide for details.


Step 2: Configure Varnish

  1. By default, Varnish listens on port 6081 and expects the backend web server on port 8080.

  2. Update your web server (Apache/Nginx) to listen on 8080 instead of 80.

  3. Configure /etc/varnish/default.vcl to point to your backend:

vcl 4.1;

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}
  1. Update /etc/systemd/system/multi-user.target.wants/varnish.service (or override with systemctl edit varnish) to listen on port 80:

ExecStart=/usr/sbin/varnishd \
-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-s malloc,1G
  1. Reload and enable Varnish:

systemctl daemon-reload
systemctl enable --now varnish

Step 3: Remove Varnish Cache

To uninstall Varnish and restore your web server:

  • RHEL/AlmaLinux/Rocky:

    dnf remove varnish
    
  • Debian/Ubuntu:

    apt remove --purge varnish
    

Then reconfigure your web server (Apache/Nginx) to listen directly on port 80 again.


Notes & Caveats

  • cPanel servers: Instead of Varnish, use WHM’s NGINX Manager for a fully supported caching solution.

  • SSL/TLS support: Varnish does not handle SSL termination natively. You must place it behind a TLS-terminating proxy (like NGINX, Hitch, or HAProxy) if you want to use HTTPS.

  • Compatibility: Varnish requires careful integration with applications such as WordPress, Magento, or Drupal. Additional VCL rules are needed to prevent caching of admin sessions and dynamic content.


✅ With these steps you can safely install or remove Varnish Cache on your VPS or dedicated server. For cPanel servers, we recommend using the built-in NGINX support instead.

Updated by SP on 02/10/2025

Was this answer helpful? 328 Users Found This Useful (336 Votes)