{"id":2136,"date":"2016-06-29T17:53:54","date_gmt":"2016-06-29T21:53:54","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2136"},"modified":"2017-04-19T15:57:05","modified_gmt":"2017-04-19T19:57:05","slug":"set-up-varnish-centos-7","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/","title":{"rendered":"How to set up Varnish on CentOS 7"},"content":{"rendered":"<p>Varnish is an HTTP accelerator, a special type of reverse proxy that caches static and dynamic content to ease the burden on web servers. It&#8217;s used by many heavily-trafficked websites, such as Facebook, Twitter and Wikipedia among others.<\/p>\n<p>Varnish is well maintained, being updated every 2 to 3 years since 2008. The newest version, Varnish 4.0, was released in 2014. Best of all, it&#8217;s open source under a two-clause BSD license so that anyone can use it to improve the speed of their website.<\/p>\n<p>The Varnish installation process is simple and will help protect your server and keep the quality of site performance high in case of a sudden spike in traffic. It&#8217;s time to install Varnish. <\/p>\n<h2>Getting Started<\/h2>\n<p>To complete this guide, you will need the following:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\">Cloud Server<\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\">Dedicated Server<\/a>) with CentOS 7 installed.<br \/>\n\u2022 LAMP stack with Apache installed<br \/>\n\u2022 Type all commands in root<\/p>\n<h2>Install Varnish<\/h2>\n<p>Add the Extra Packages for Enterprise Linux, or EPEL, repository to your system. This is where Varnish lives.<\/p>\n<p><code>yum -y install epel-release<\/code><\/p>\n<p>Install the Varnish package. Ideally, ensure that your system is fully up-to-date beforehand.<\/p>\n<p><code>yum -y install varnish<\/code><\/p>\n<p>Upon installation, Varnish will be set to listen on port 6081 as its default. You&#8217;ll want to switch the default port that Varnish uses to an HTTP port. We&#8217;ll choose 8080 for the purposes of this tutorial.<\/p>\n<p>There are three values in three files that you&#8217;ll need to change in order to do this. <\/p>\n<p>First, open the Varnish configuration file in an editor.<\/p>\n<p><code>nano \/etc\/varnish\/varnish.params<\/code><\/p>\n<p>Find the line VARNISH_LISTEN_PORT and change the value<\/p>\n<p><code class=\"gris\">VARNISH_LISTEN_PORT=6081<\/code><\/p>\n<p>to<\/p>\n<p><code class=\"gris\">VARNISH_LISTEN_PORT=80<\/code><\/p>\n<p>Next, open up the Varnish VCL configuration file.<br \/>\n<code>nano \/etc\/varnish\/default.vcl<\/code><\/p>\n<p>Make sure the port is set to 8080 in this block.<br \/>\n<code class=\"gris\">backend default {<br \/>\n    .host = \"127.0.0.1\";<br \/>\n    .port = \"8080\";<\/code><\/p>\n<p>Finally, open your Apache configuration file.<br \/>\n<code>nano \/etc\/httpd\/conf\/httpd.conf<\/code><\/p>\n<p>Look for the line Listen 80.<br \/>\n<code class=\"gris\">#Listen 12.34.56.78:80<br \/>\nListen 80<\/code><\/p>\n<p>Change it to read Listen 8080.<br \/>\n<code class=\"gris\">#Listen 12.34.56.78:80<br \/>\nListen 8080<\/code><\/p>\n<p>After you&#8217;ve made the above changes, restart both Apache and Varnish. This will make sure that they recognize the port change.<br \/>\n<code>systemctl restart httpd.service<br \/>\nsystemctl restart varnish.service<\/code><\/p>\n<p>Check that your webserver and Varnish are working.<br \/>\n<code>curl -I http:\/\/your_ip <---------------- Change for your main IP<\/code><\/p>\n<p><code class=\"gris\">HTTP\/1.1 200 OK<br \/>\nDate: Tue, 21 Jun 2016 10:15:43 GMT<br \/>\nServer: Apache\/2.4.6 (CentOS)<br \/>\nLast-Modified: Thu, 16 Oct 2014 13:20:58 GMT<br \/>\nETag: \"1321-5058a1e728280\"<br \/>\nAccept-Ranges: bytes<br \/>\nContent-Length: 4897<br \/>\nContent-Type: text\/html; charset=UTF-8<br \/>\nX-Varnish: 98321<br \/>\nAge: 0<br \/>\nVia: 1.1 varnish-v4<br \/>\nConnection: keep-alive<\/code><\/p>\n<p>Check your Varnish stats.<br \/>\n<code>varnishstat<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>Now that installation is concluded, Varnish is serving all site content to users. If your website is particularly heavy, you should see an immediate improvement in access speed. If this guide was helpful to you, kindly share it with others who may also be interested. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Varnish is an HTTP accelerator, a special type of reverse proxy that caches static and dynamic content to ease the burden on web servers. It&#8217;s used by many heavily-trafficked websites, such as Facebook, Twitter and Wikipedia among others. Varnish is well maintained, being updated every 2 to 3 years since 2008. The newest version, Varnish<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-2136","post","type-post","status-publish","format-standard","hentry","category-web-hosting","operating_system-centos-7"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to set up Varnish on CentOS 7 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to install Varnish on your CentOS 7 Server. Read now &amp; start caching static and dynamic content!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to set up Varnish on CentOS 7 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to install Varnish on your CentOS 7 Server. Read now &amp; start caching static and dynamic content!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-06-29T21:53:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-04-19T19:57:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/\"},\"author\":{\"name\":\"GloboTech Communications\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\"},\"headline\":\"How to set up Varnish on CentOS 7\",\"datePublished\":\"2016-06-29T21:53:54+00:00\",\"dateModified\":\"2017-04-19T19:57:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/\"},\"wordCount\":374,\"commentCount\":0,\"articleSection\":[\"Web Hosting\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/\",\"url\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/\",\"name\":\"How to set up Varnish on CentOS 7 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#website\"},\"datePublished\":\"2016-06-29T21:53:54+00:00\",\"dateModified\":\"2017-04-19T19:57:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to install Varnish on your CentOS 7 Server. Read now & start caching static and dynamic content!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/set-up-varnish-centos-7\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to set up Varnish on CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#website\",\"url\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\\\/\\\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to set up Varnish on CentOS 7 - Globo.Tech","description":"This tutorial will show you how to install Varnish on your CentOS 7 Server. Read now & start caching static and dynamic content!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/","og_locale":"en_US","og_type":"article","og_title":"How to set up Varnish on CentOS 7 - Globo.Tech","og_description":"This tutorial will show you how to install Varnish on your CentOS 7 Server. Read now & start caching static and dynamic content!","og_url":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/","og_site_name":"Globo.Tech","article_published_time":"2016-06-29T21:53:54+00:00","article_modified_time":"2017-04-19T19:57:05+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/#article","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/"},"author":{"name":"GloboTech Communications","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"headline":"How to set up Varnish on CentOS 7","datePublished":"2016-06-29T21:53:54+00:00","dateModified":"2017-04-19T19:57:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/"},"wordCount":374,"commentCount":0,"articleSection":["Web Hosting"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/","url":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/","name":"How to set up Varnish on CentOS 7 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-06-29T21:53:54+00:00","dateModified":"2017-04-19T19:57:05+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to install Varnish on your CentOS 7 Server. Read now & start caching static and dynamic content!","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/set-up-varnish-centos-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to set up Varnish on CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=2136"}],"version-history":[{"count":5,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2136\/revisions"}],"predecessor-version":[{"id":2867,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2136\/revisions\/2867"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}