How to Install Varnish on CentOS 7 Apache Web Server
In this tutorial we are going to learn how to Install varnish cache on CentOS 7 and How to Configure varnish cache for CentOS 7 Apache Web Server. Varnish cache is a great way to reduce your server load and improve the response time of your website.
If you haven’t installed Apache Web Server on your CentOS 7 server, Read the following tutorial to Learn How to Install and Configure Apache Web Server on CentOS 7.
To install Varnish on Centos 7, Following are the steps we are going to do.
- Install epel release on CentOS 7.
- Install varnish cache.
- Configure varnish for CentOS 7 Apache Web Server.
Install epel release on CentOS 7
The Varnish HTTP accelerator package does not come with the CentOS 7 default software repository. So in order to install varnish on CentOS 7, we have to use epel repository.
yum install epel-release
Install Varnish Cache on CentOS 7
Now we can install varnish on CentOS 7 using yum install command.
yum install varnish
Then start and enable the varnish service using systemctl command.
systemctl start varnish.service
systemctl enable varnish.service
Configure Varnish for CentOS 7 Apache Web Server
We need to configure varnish to handle http (port 80) traffic. So first we need to configure apache web server to run on a different port.
Change Apache Port in CentOS 7
To change the Apache port on CentOs 7, open the /etc/httpd/conf/httpd.conf file.
vim /etc/httpd/conf/httpd.conf
Find the line that reads Listen 80 and Replace it with the following line.
Listen 127.0.0.1:8080
If you have configured Apache virtual hosts, You need to change the Listen port on all Virtual hosts too.
<VirtualHost *:8080>
Make sure to restart the apache server after the changes are made.
systemctl restart httpd
Change Varnish Listen port to port 80
First, open the /etc/varnish/varnish.params file.
vim /etc/varnish/varnish.params
Locate the line
VARNISH_LISTEN_PORT=6081
Change it to,
VARNISH_LISTEN_PORT=80
Configure varnish to handle HTTP Traffic
Open the /etc/varnish/default.vcl file.
vim /etc/varnish/default.vcl
Make sure the backend default section is similar to the following.
backend default {
.host = “127.0.0.1”;
.port = “8080”;
}
To finish the configuration, restart the CentOS 7 Varnish Service using systemctl command.
systemctl restart varnish.service
Ok! Now you have successfully configured varnish caching on CentOS 7 HTTPD Web Server.
Summary – Install Varnish CentOS 7 HTTPD Server
In this tutorial we learned how to install varnish on CentOS 7. First, we installed the varnish on CentOS 7 using epel repository. Then we configured varnish to handle HTTP traffic on CentOS 7 Apache Web Server.