How to configure Varnish with Apache on Ubuntu and CentOS
Varnish is used to make a website load speedily, as the cache is stored in RAM; to lowers down the server load, specifically CPU works; and to gain more and more visitors.
It can be installed and run either on Apache or Nginx.Use the following steps to install and configure Varnish on CentOS.
Step–1: Get the rpm for Varnish using the following command.
rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release/varnish-release-3.0-1.el5.centos.noarch.rpm
Step–2: Use the following command to install Varnish
yum install varnish
Step – 3: Modify or change the VARNISH_LISTEN_PORT=6081 line to port 80, use the following command: VARNISH_LISTEN_PORT=80
Step – 4: Now, you need to save the file and edit the default configuration file of Varnish. The following command is used for this purpose: vi /etc/varnish/default.vcl
Step – 5: Transform the backend default port to port 81 rather. As a result, the backend section will be as follows:
backend default {
.host = "127.0.0.1";
.port = "81";
}
Step – 6: To configure Apache on port 81, edit the apache httpd.conf. For editing the file, the following command is used:
vi /etc/httpd/conf/httpd.conf
Also, modify the listen line to port 81
Step – 7: Alter or change iptables firewall to permit connections on port 81
Using the below command to edit the iptables configuration file
vi /etc/sysconfig/iptables
Before the COMMIT, the following lines needs to be added.
-A INPUT -m state --state NEW -m tcp -p tcp --dport 81 -j ACCEPT
-A OUTPUT -m state --state NEW -m tcp -p tcp --dport 81 -j ACCEPT
Further, save the file and after that restart iptables
service iptables restart
Step – 8: Configure SELinux to connect apache on port 81, and then restart apache
vi /etc/selinux/config
Change SELINUX=enforcing to
SELINUX=permissive
Now, save the file and restart apache with the following command
service httpd restart
Step – 9: Configure and start Varnish
chkconfig varnish on
service varnish start
Was this answer helpful?
Also Read
Powered by WHMCompleteSolution