How Can We Help?

How to Install Varnish Cache with Apache on CentOS 7

Table of Content

Introduction

In this article you will know How to Install Varnish Cache with Apache on CentOS 7.

As an HTTP caching proxy server, Varnish is a powerful tool. It's a reverse proxy for your web server (Apache or Nginx) and an HTTP accelerator. Sites with lots of visitors and a lot of notoriety have used Varnish.

Step 1 - Install and configure Apache on CentOS 7

Using the CentOS 7 repository, we will install Apache/httpd web server and set up the server to listen on port 8080. Follow the yum command below to set up Apache/httpd.

# yum -y install httpd

Use the following commands to start the httpd service and set it to automatically launch with the system after installation is complete.

# systemctl start httpd
# systemctl status httpd

# systemctl enable httpd

This means that the server's httpd service has started. Netstat is displayed below; use it to verify

# netstat -plntu

Step 2 - Configure Apache on port 8080

# vi /etc/httpd/conf/httpd.conf

Replace "80" with "8080" on the 'Listen' line to redirect traffic from port 80 to port 8080.

Now that everything has been set up, make sure there are no problems by testing it. Then, the apache/httpd service must be restarted.

# apachectl configtest

# systemctl restart httpd.service

Step 3 - Install Varnish on CentOS 7

Use the following command to set up the EPEL repository.

# yum -y install epel-release

Finally, use the yum command below to install Varnish from the EPEL repository.

# yum -y install varnish

The following systemctl commands should be used to start Varnish and register it for automatic startup after installation is complete.

# systemctl start varnish
# systemctl status varnish

# systemctl enable varnish

Step 4 - Configure Varnish as a reverse proxy for Apache

Following its installation, Varnish will be set up as a reverse proxy between the Apache web server and the client. By default, Varnish will use port 80 for HTTP traffic. You can change the default settings for Varnish by editing the file named "default.vcl" in the Varnish configuration directory.

# cd /etc/varnish
# vi default.vcl

Lay out the structure for the default backend. This is the configuration for our Apache web server, which is listening on port 8080.

Step 5 Save and exit. Now restart Varnish

As a next step, set up Varnish to use port 80 for HTTP traffic. You can customize Varnish by modifying the 'varnish.params' file in the installation's root directory. The file's 'VARNISH LISTEN PORT' line should be updated to point to port 80 for HTTP. VARNISH LISTEN PORT=80

# cd /etc/varnish
# vi varnish.params

# systemctl restart varnish httpd

Step 6 - Testing

# cd /var/www/html/
# echo '<h1><center> varnish- Apache - quicknotpad-tutorial</center></h1>' > index.html
# netstat -tlpn

 This command is used to shown, Varnished :::8080

# curl -I 127.0.0.1

Conclusion

Hopefully this article has helped you to understand How to install Varnish Cache with Apache on CentOS 7. 

Thank You 🙂

Table of Contents