BiswasHost BiswasHost
How to Install & Configure Varnish on AlmaLinux 9 / RockyLinux 9 / RHEL 9 (CWP)
Cart
Your cart is empty Browse Products →

How to Install & Configure Varnish on AlmaLinux 9 / RockyLinux 9 / RHEL 9 (CWP)

This guide explains how to install and configure Varnish Cache on EL9-based systems when using CWP (CentOS Web Panel) with the Apache + Nginx + Varnish stack.


⚠️ Important Note

On AlmaLinux 9 / RockyLinux 9 / RHEL 9, Varnish may not install automatically via CWP.
This guide provides a manual workaround to install and configure it correctly.


✅ Step 1: Install Web Server Stack from CWP

Login to CWP Admin Panel

Go to:

WebServer Settings → Select WebServers

Choose:

Apache + Nginx + Varnish

Click Save & Rebuild Configuration

👉 At this stage, Varnish may appear as missing — proceed to Step 2.


✅ Step 2: Install Varnish Manually

Run the following commands:

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

✅ Step 3: Change Varnish Port (6081 → 82)

Edit the Varnish systemd service file:

nano /usr/lib/systemd/system/varnish.service

🔍 Find this line:

ExecStart=/usr/sbin/varnishd -a :6081 ...

✏️ Replace with:

ExecStart=/usr/sbin/varnishd -a :82 -f /etc/varnish/default.vcl -s malloc,256m

✅ Step 4: Reload & Start Varnish

Run:

systemctl daemon-reexec
systemctl daemon-reload
setenforce 0
systemctl restart varnish

🔍 Verify Varnish is running:

ss -tulnp | grep varnish
systemctl status varnish

🔒 (Optional) Protect Configuration File

Lock the service file to prevent CWP overwriting:

chattr +i /usr/lib/systemd/system/varnish.service

To unlock later:

chattr -i /usr/lib/systemd/system/varnish.service

✅ Step 5: Fix Backend Configuration (Important)

If your website shows 503 Backend fetch failed, update Varnish backend.

Edit:

nano /etc/varnish/default.vcl

🔍 Replace this:

backend default {
    .host = "127.0.0.1";
    .port = "8080";
}

✅ With your server IP and Apache port:

backend default {
    .host = "YOUR_SERVER_IP";
    .port = "8181";
}

Example:

.host = "109.50.345.14";

🔒 (Optional) Protect VCL file:

chattr +i /etc/varnish/default.vcl

Unlock if needed:

chattr -i /etc/varnish/default.vcl

✅ Step 6: Restart Varnish

systemctl restart varnish

✅ Step 7: Test Your Website

Visit your website in a browser.

✔ Website should load normally
✔ No more 503 Backend fetch failed errors


🧪 Optional: Verify Varnish is Working

curl -I http://yourdomain.com

Look for:

Via: 1.1 varnish

🔥 Final Architecture

ServicePort
Nginx80 / 443
Varnish82
Apache8181 / 8443

⚠️ Troubleshooting Tips

Ensure Apache is running on port 8181

Disable SELinux temporarily if issues occur:

setenforce 0

Check logs:

systemctl status varnish
journalctl -xe

✅ Conclusion

By following this guide, you can successfully install and configure Varnish Cache on EL9 systems with CWP, even though it is not fully supported natively.

 

Please rate this article to help us improve our Knowledge Base.

1 0