Configure Varnish with Apache on Ubuntu
Setup and Configure Varnish with Apache on Ubuntu
To perform all the steps given here, you will need to have both a user with sudo privileges and apache installed on your virtual private server.
Please go through the third and fourth steps of the initial ubuntu server setup to create a user with sudo privileges.
It is very easy to install Apache on your VPS. It can be installed with a single command from the apt-get repository.
First of all, The varnish site recommends everyone to instal the varnish package through their own repository.
Well for that, you can start that process by grabbing their repository:
Finally, you can now update apt-get and install varnish.
Now you can proceed with the configuration of Varnish with Apache on Ubuntu once you are done with the Apache and varnish installation, you can start configuring them to ease the load on your server from all the future visitors.
Now open the /etc/default/varnish file:
Uncomment all of the lines under “DAEMON_OPTS”—under Alternative 2, and make theconfiguration match the following code:
Once you save and exit out of that file, open up the default.vcl file:
Although Apache listens on port 80 by default, we will change the settings for it later. Within this file, we will tell varnish to look for the content on port 8080. The configuration should like this:
So far we have told varnish that Apache ports will be running on 8080. However the default settings for apache are still on port 80. We will correct the discrepancy now.
Open up the Apache ports file:
Change the port number for both the NameVirtualHost and the Listen line to port 8080, and the virtual host should only be accessible from the localhost. The configuration should look like this:
Change these settings in the default virtual host file as well:
The Virtual Host should also be set to port 8080, and updated line looks like this:
Save and exit the file and proceed to restart Apache and Varnish to make the changes effective.
Accessing your domain should forthwith take you to the varnish cached version, and you can see all the details of varnishes workings there by using the following given command:
If you facing any error then use this link
Reference link https://www.varnish-cache.org/installation/ubuntu