Superior Administrator _.:=iTake=:._ Posted February 18, 2019 Superior Administrator Report Posted February 18, 2019 In this tutorial we can check how to Configure and Install Varnish on CentOS/Ubuntu server. Varnish is the most powerful open source HTTP engine/reverse HTTP proxy that has the capability to increase the site speed, especially when there is high traffic on the site. Varnish Cache visits your page only once for caching the page and all the future request for that page will be served by varnish cache Install varnish Before installing varnish, we need to add varnish repositories to the server. For Ubuntu Users [iCODE]# curl This is the hidden content, please Sign In or Sign Up | sudo apt-key add – # apt-get update # apt-get install varnish[/iCODE] For CentOS Users [iCODE]# yum install -y epel-release # yum update # yum install -y varnish[/iCODE] Configuring Varnish on both Ubuntu and CentOS After installation, we need to configure varnish to reduce the load on the server. For Ubuntu Users Search and uncomment the lines under “DAEMON_OPTS” on the varnish configuration file /etc/default/varnish and edit the lines similar to the following. [iCODE]# vi /etc/default/varnish DAEMON_OPTS=”-a :80 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,256m”[/iCODE] After saving this file open varnish default file which tells varnish to look for server content. Edit this file to tell varnish to look for the content on port 8080. The code will be similar to the below example. [iCODE]# vi /etc/varnish/default.vcl backend default { .host = “127.0.0.1”; .port = “8080”; }[/iCODE] For CentOS users. Edit varnish configuration file to change the varnish port. [iCODE]# vi /etc/varnish/varnish.params VARNISH_LISTEN_PORT=80[/iCODE] Save the file and open the default file of varnish to look the content on port 8080. The code should be similar to the following example. [iCODE]# vi /etc/varnish/default.vcl backend default { .host = “127.0.0.1”; .port = “8080”; }[/iCODE] Configure apache to work with varnish By default, apache is listening to port 80. We have to change the port for apache to 8080 to run it behind varnish. For Ubuntu Users. Edit the port.conf file to change apache port to 8080. The file should be similar to the example below. [iCODE]# vi /etc/apache2/ports.conf NameVirtualHost 127.0.0.1:8080 Listen 127.0.0.1:8080[/iCODE] Also, edit the apache configuration file to change the port. [iCODE]# vi /etc/apache2/sites-available/default <VirtualHost 127.0.0.1:8080>[/iCODE] Save this file and restart both services to enable the changes. [iCODE]# service apache2 restart # service varnish restart[/iCODE] For CentOS users Edit apache configuration file to change the port to 8080. [iCODE]# vi /etc/httpd/conf/httpd.conf Listen 8080[/iCODE] Restart both services to reflect the changes. [iCODE]# systemctl restart varnish # systemctl restart httpd[/iCODE] After the installation, you can verify whether the vanish is working or not by using the following command. [iCODE]# curl -I This is the hidden content, please Sign In or Sign Up [/iCODE] Then the output should be something similar to the following: [iCODE]HTTP/1.1 200 OK Date: Wed, 04 Nov 2015 10:21:07 GMT Server: Apache/2.4.6 (CentOS) Last-Modified: Fri, 02 Oct 2015 10:36:53 GMT ETag: “6c-5211cdbf61c14” Content-Length: 108 Content-Type: text/html; charset=UTF-8 X-Varnish: 32770 Age: 0 Via: 1.1 varnish-v4 Connection: keep-aliveHTTP/1.1 200 OK Date: Wed, 04 Nov 2015 10:21:07 GMT Server: Apache/2.4.6 (CentOS) Last-Modified: Fri, 02 Oct 2015 10:36:53 GMT ETag: “6c-5211cdbf61c14” Content-Length: 108 Content-Type: text/html; charset=UTF-8 X-Varnish: 32770 Age: 0 Via: 1.1 varnish-v4 Connection: keep-alive [/iCODE][/indent] 1
Recommended Posts