{"id":4393,"date":"2019-05-01T21:41:43","date_gmt":"2019-05-01T16:11:43","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4393"},"modified":"2019-05-01T22:07:20","modified_gmt":"2019-05-01T16:37:20","slug":"configure-varnish-with-apache-on-centos-7","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/configure-varnish-with-apache-on-centos-7\/","title":{"rendered":"Configure Varnish With Apache On CentOS 7"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Configure Varnish With Apache On CentOS 7<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Date published: 01\/05\/2019<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Introduction<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Varnish Cache is a web application accelerator also known as a<strong> caching HTTP reverse proxy<\/strong>.  Most certainly, you will install it in front of any server that speaks HTTP and configure it to cache the contents. <br><br>Varnish Cache is really, very fast and handles request at high speed. It typically speeds up delivery with a factor of 300 &#8211; 1000x, depending on your architecture.<\/p>\n\n\n\n<ul class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><li class=\"blocks-gallery-item\"><figure><img fetchpriority=\"high\" decoding=\"async\" width=\"668\" height=\"322\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Screen-Shot-2019-05-01-at-5.51.52-PM.png\" alt=\"\" data-id=\"4394\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=4394\" class=\"wp-image-4394\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Screen-Shot-2019-05-01-at-5.51.52-PM.png 668w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2019\/05\/Screen-Shot-2019-05-01-at-5.51.52-PM-300x145.png 300w\" sizes=\"(max-width: 668px) 100vw, 668px\" \/><figcaption>Varnish Cache webserver as Frontend and Apache webserver as backend<\/figcaption><\/figure><\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">prerequisite<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>However, we need server running CentOS 7 with Apache installed with any version.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Procedure for installation of Varnish<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before installing Varnish in your server, you will have to install the EPEL repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install -y epel-release<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">For instance, install varnish in server<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code> yum install -y varnish<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After installation, you will need to start Varnish and enable it to start on boot.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl start varnish\nsudo systemctl enable varnish<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Moreover, check the status of Varnish.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status varnish<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Likewise, check the version of Varnish <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo varnishd -V<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-varnish\">Configuration of Varnish setup<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The default varnish configuration file will be located in the <code><strong>\/etc\/varnish<\/strong><\/code><strong>\u00a0<\/strong>directory in CentOS 7. <br><br>To make Varnish work in front of Apache, you will need to set up some basic configurations like given details below.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By default Varnish listens on\u00a0<code><strong>port 6081<\/strong><\/code>. Use network tools such as netstat for confirmation.<br><br> You will need to change port <code>6081<\/code>\u00a0to\u00a0<code>80<\/code>\u00a0<strong>so that website requests access the Varnish cache first<\/strong>.  Similarly, you can do this by editing the <code><strong>varnish.params<\/strong><\/code>\u00a0config file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/varnish\/varnish.params\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Change <strong>VARNISH_LISTEN_PORT<\/strong>\u00a0from\u00a0<code>6081<\/code>\u00a0to\u00a0<code>80<\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">VARNISH_LISTEN_PORT=80\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save the file, then open the\u00a0<code><strong>default.vcl<\/strong><\/code>\u00a0file. This file tells varnish to look for the server content:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/varnish\/default.vcl\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">All the above, update the Varnish to get the content on port <code>8080<\/code>.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">backend default {\n.host = \"127.0.0.1\";\n.port = \"8080\";\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"configure-apache-to-work-with-varnish\">Configure Apache [backend] To Work With Varnish<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">By default Apache listens on port\u00a0<code><strong>80<\/strong><\/code>. <br><br>Similarly in the vein, you need to make Apache to run <strong>behind Varnish caching<\/strong> by changing the default Apache port to <code>8080<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this, edit the\u00a0<code>httpd.conf<\/code> config file of Apache:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/httpd\/conf\/httpd.conf\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Search for\u00a0<code><strong>Listen 80<\/strong><\/code>\u00a0and replace it with\u00a0<code><strong>Listen 8080<\/strong><\/code>:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">Listen 8080\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Save and close the file, restart Apache and Varnish to reflect the changes in port.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apachectl restart\nsudo systemctl restart varnish\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Test the web severs<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now we have successfully configured  Varnish and Apache running together. <br><br>To verify that Varnish is on and working, you can use the <code><strong>curl<\/strong><\/code><strong>command<\/strong> to view the HTTP header:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">curl -I http:\/\/localhost\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see the <strong>output<\/strong> something like this:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">HTTP\/1.1 200 OK\nDate: Wed, 01 May 2019 09:49:37 GMT\nServer: Apache\/2.4.6 (CentOS)\nLast-Modified: Fri, 18 Apr 2019 11:39:13 GMT\nETag: \"6c-5211cdbf61c14\"\nContent-Length: 108\nContent-Type: text\/html; charset=UTF-8\nX-Varnish: 32770\nAge: 0\nVia: 1.1 varnish-v4\nConnection: keep-alive<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That&#8217;s it<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for using&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/\">pheonix solutions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You find this tutorial helpful? Share with your friends to keep it alive.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Configure Varnish With Apache On CentOS 7 Date published: 01\/05\/2019 Introduction Varnish Cache is a web application accelerator also known [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1019],"tags":[635,633,634],"class_list":["post-4393","post","type-post","status-publish","format-standard","hentry","category-cloud-aws","tag-apache-web-server","tag-centos7","tag-varnish-cache-server","psol-cat-cloud-aws"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-18R","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4393"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4393\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}