Varnish is an HTTP reverse proxy tool that you can use to reduce your website load and avoid lags. It stores client requests in RAM and eliminates the need to send a client request to the web service on the next visit. In this way, your website will load faster for the visitor.
If the content requested by the user is not in the cache, Varnish connects to the web server and stores the content for the next request. The services in this caching process work as two different layers.

VCL, an abbreviation of Varnish Configuration Language, is a configuration language used to provide Varnish controls. It is a unique Varnish application language used to perform request processing, routing, caching, and many other operations.
Varnish installation
Here, we have a video version of our tutorial if you want to check:
The Varnish application can be installed on distributions such as Ubuntu, Debian, CentOS, and Red Hat Enterprise Linux. In this article, we will install Varnish on the AlmaLinux operating system.
Let’s check the HTTP Response values of the website before installation with the help of curl. You should replace the IP address with your website’s IP address, or you can directly write your address as well:
curl -I https://yourwebsite.com
Varnish can be installed from the AlmaLinux repo, but if the package manager is out of date, it will install an old version. To avoid this, it would be healthier to install Varnish from the official site.
First, disable the Varnish service from the DNF package manager:
sudo dnf module disable varnish
Then install the EPEL package manager to allow Varnish dependencies to be installed:
sudo dnf install epel-release -y
The EPEL installation was successful. Go to the official Varnish Cache site and copy and paste the code below into the terminal screen.
. /etc/os-release
sudo tee /etc/yum.repos.d/varnishcache_varnish60lts.repo > /dev/null <<-EOF
[varnishcache_varnish60lts]
name=varnishcache_varnish60lts
baseurl=https://packagecloud.io/varnishcache/varnish60lts/el/${VERSION_ID%%.*}/$(arch)
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packagecloud.io/varnishcache/varnish60lts/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300
EOF
You can copy the command from the Varnish installation tutorial page to register the latest version to the EPEL repository.
As the registration completes, you can now install Varnish Cache 6.0 LTS by using the following command:
dnf install varnish -y
Configuration
Changing Varnish ports
After the Varnish installation is finished, you can manage its settings by running the varnishd parameter. The varnishd process is managed by systemd. To make changes to the configuration file, copy and paste the following command to the terminal screen:
nano /usr/lib/systemd/system/varnish.service
While installing Varnish Cache, it uses port 6081 so that it does not conflict with the web service. Change port 6081 to 80 in the -a parameter in the ExecStart field so that the Varnish Cache service can listen on port 80. Then we will make settings on the Nginx service. Save this file and exit.
Setting Varnish listening port
No port changes have been made on the Nginx yet, but we need to specify which port to listen to the Varnish Cache service. In this article, port 8080 will be used. So check the .port field and change it to 8080. Then save the file and exit.
nano /etc/varnish/default.vcl
Changing ports on Nginx
To change the port of the Nginx service, go to the file path below and follow the steps, or quickly perform the following steps with the sed command:
nano /etc/nginx/nginx.conf
You can also quickly perform the operations above using the command below:
sudo find /etc/nginx -name '*.conf' -exec sed -r -i 's/\blisten ([^:]+:)?80\b([^;]*);/listen \18080\2;/g' {} ';'
As the steps above complete, restart the Nginx service:
systemctl reload nginx.service
Then enable the Varnish Cache service:
systemctl enable varnish
systemctl start varnish.service
You have completed the installation of Varnish on AlmaLinux. To verify the installation, check the HTTP response list again with the curl command:
curl -I https://yourwebsite.com