<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Varnish Cache on CentOS 8 Archives - Linux Windows and android Tutorials</title>
	<atom:link href="https://www.osradar.com/tag/varnish-cache-on-centos-8/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.osradar.com</link>
	<description>tutorials and news and Seurity</description>
	<lastBuildDate>Fri, 15 Nov 2019 08:33:23 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.8.12</generator>
	<item>
		<title>How to Install Varnish cache 6 for Apache/Nginx on Centos / RHEL 8</title>
		<link>https://www.osradar.com/how-to-install-varnish-cache-6-for-apache-nginx-on-centos-rhel-8/</link>
					<comments>https://www.osradar.com/how-to-install-varnish-cache-6-for-apache-nginx-on-centos-rhel-8/#respond</comments>
		
		<dc:creator><![CDATA[sabi]]></dc:creator>
		<pubDate>Fri, 15 Nov 2019 08:33:21 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Centos 8]]></category>
		<category><![CDATA[Install Varnish]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[servers]]></category>
		<category><![CDATA[Varnish Cache on CentOS 8]]></category>
		<guid isPermaLink="false">https://www.osradar.com/?p=15600</guid>

					<description><![CDATA[<p>What is Varnish Cache? As you know about Cache, it enhances the loading speed by saving web pages, cookies and other data. It saves into memory the requested data and provide faster results. Because of its faster response, it is also used in Linux like Centos to provide faster results. It is also called caching [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/how-to-install-varnish-cache-6-for-apache-nginx-on-centos-rhel-8/">How to Install Varnish cache 6 for Apache/Nginx on Centos / RHEL 8</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3><strong>What is Varnish Cache?</strong></h3>



<p>As you know about Cache, it enhances the loading speed by saving web pages, cookies and other data. It saves into memory the requested data and provide faster results. Because of its faster response, it is also used in Linux like Centos to provide faster results. It is also called <strong>caching HTTP reverse proxy</strong> which is a leading web application accelerator, capturing the visits and boost upon delivery on again request. It saves the web servers time by providing them the same data as saved earlier. Hence, in this tutorial we are going to learn how you can install and configure Varnish Cache 6 on CentOS 8 / RHEL 8.</p>



<h3><strong>Step 1: Update System</strong></h3>



<p>Make sure your system is up-to-date.</p>



<pre class="wp-block-verse">sudo dnf -y update</pre>



<h3><strong>Step 2: Install Varnish Cache 6 on CentOS 8 / RHEL 8</strong></h3>



<p>You can use the following command to install varnish cache on CentOS / RHEL 8.</p>



<pre class="wp-block-verse">sudo dnf install @varnish</pre>



<p>Allow to continue with the installation process by pressing y key.</p>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="734" height="499" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/varnish-install-alert.png" alt="" class="wp-image-15601" srcset="https://www.osradar.com/wp-content/uploads/2019/11/varnish-install-alert.png 734w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-install-alert-300x204.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-install-alert-696x473.png 696w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-install-alert-618x420.png 618w" sizes="(max-width: 734px) 100vw, 734px" /></figure></div>



<p>If you want to see more information on installed package you can type the following command.</p>



<pre class="wp-block-verse">rpm -qi varnish</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="732" height="501" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/rpm-qi-varnish.png" alt="" class="wp-image-15602" srcset="https://www.osradar.com/wp-content/uploads/2019/11/rpm-qi-varnish.png 732w, https://www.osradar.com/wp-content/uploads/2019/11/rpm-qi-varnish-300x205.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/rpm-qi-varnish-218x150.png 218w, https://www.osradar.com/wp-content/uploads/2019/11/rpm-qi-varnish-696x476.png 696w, https://www.osradar.com/wp-content/uploads/2019/11/rpm-qi-varnish-614x420.png 614w" sizes="(max-width: 732px) 100vw, 732px" /></figure></div>



<p><strong>Important things to Remember:</strong></p>



<ul><li>Main configuration file of Varnish can be found in <strong>/etc/varnish/default.vcl</strong></li><li>Secret file of Varnish is in<strong> /etc/varnish/secret</strong></li><li>Cashe executable binary is found in<strong> /usr/sbin/varnishd</strong></li><li>Systemd unit file is in <strong>/lib/systemd/system/varnish.service</strong></li></ul>



<h3><strong>Step 3: Start and Enable Varnish Cache Services</strong></h3>



<p>Use the following command to start &amp; enable Varnish Cache services.</p>



<pre class="wp-block-verse">sudo systemctl enable --now varnish</pre>



<p>Make sure status is working properly</p>



<pre class="wp-block-verse">systemctl status varnish</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="735" height="493" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/varnish-status.png" alt="" class="wp-image-15603" srcset="https://www.osradar.com/wp-content/uploads/2019/11/varnish-status.png 735w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-status-300x201.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-status-696x467.png 696w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-status-626x420.png 626w" sizes="(max-width: 735px) 100vw, 735px" /></figure></div>



<h3><strong>Step 4: Configure Varnish Cache for Nginx/Apache Web Server</strong></h3>



<p>As Varnish sits in front of a web server as a caching HTTP Reverse Proxy, so it speeds up web servers.<br>
In this tutorial we are using Nginx/Apache HTTPD server but you can use your favourite one.</p>



<p>For Apache</p>



<pre class="wp-block-verse">sudo dnf -y install @httpd</pre>



<p>For Nginx</p>



<pre class="wp-block-preformatted">sudo dnf -y install @nginx</pre>



<h5>1. <strong>Configure Nginx with Varnish</strong></h5>



<p>By default, TCP port 80 is being used by Nginx, change it to listen to 8080 port because Varnish Cache will use port 80.</p>



<pre class="wp-block-verse">sudo vi /etc/nginx/nginx.conf</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="675" height="122" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/listen-port-nginx.png" alt="" class="wp-image-15605" srcset="https://www.osradar.com/wp-content/uploads/2019/11/listen-port-nginx.png 675w, https://www.osradar.com/wp-content/uploads/2019/11/listen-port-nginx-300x54.png 300w" sizes="(max-width: 675px) 100vw, 675px" /></figure></div>



<p>For Virtual Hosting feature, edit the relevant confiuguration file,</p>



<pre class="wp-block-verse">sudo vi /etc/nginx/conf.d/mysite.conf</pre>



<p>After it, restart Nginx</p>



<p>sudo systemctl restart nginx</p>



<p>Double-check your settings</p>



<pre class="wp-block-verse">ss -tunelp | grep 8080</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="725" height="216" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/settings-nginx.png" alt="" class="wp-image-15606" srcset="https://www.osradar.com/wp-content/uploads/2019/11/settings-nginx.png 725w, https://www.osradar.com/wp-content/uploads/2019/11/settings-nginx-300x89.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/settings-nginx-696x207.png 696w" sizes="(max-width: 725px) 100vw, 725px" /></figure></div>



<h5>2.<strong> Configure Apache with Varnish</strong></h5>



<p>For Apache web server, make sure to set listen port to 8080.</p>



<pre class="wp-block-verse">sudo vi /etc/httpd/conf/httpd.conf</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="724" height="511" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/apache-listen-port.png" alt="" class="wp-image-15608" srcset="https://www.osradar.com/wp-content/uploads/2019/11/apache-listen-port.png 724w, https://www.osradar.com/wp-content/uploads/2019/11/apache-listen-port-300x212.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/apache-listen-port-100x70.png 100w, https://www.osradar.com/wp-content/uploads/2019/11/apache-listen-port-696x491.png 696w, https://www.osradar.com/wp-content/uploads/2019/11/apache-listen-port-595x420.png 595w" sizes="(max-width: 724px) 100vw, 724px" /></figure></div>



<p>After it, restart Apache.</p>



<pre class="wp-block-verse">sudo systemctl restart httpd</pre>



<h5>3. <strong>Configure Varnish Cache Server</strong></h5>



<p>Set Listen port for Varnish Cache to 80.</p>



<pre class="wp-block-verse">sudo vi /etc/systemd/system/multi-user.target.wants/varnish.service</pre>



<p>Edit the line starting with <strong>ExecStar</strong>t, and change from:</p>



<pre class="wp-block-verse">ExectStart=/usr/sbin/varnishd -a :6081 -f /etc/varnish/default.vcl -s malloc,256m</pre>



<p>To:</p>



<pre class="wp-block-verse">ExectStart=/usr/sbin/varnishd -a :80 -f /etc/varnish/default.vcl -s malloc,256m</pre>



<p>Now, restart Varnish systemd services.</p>



<pre class="wp-block-verse">sudo systemctl daemon-reload<br>sudo systemctl restart varnish</pre>



<p>Make sure that Varnish is listening the correct port.</p>



<pre class="wp-block-verse">sudo systemctl status varnish</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="733" height="499" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/varnish-staus-after-restart.png" alt="" class="wp-image-15609" srcset="https://www.osradar.com/wp-content/uploads/2019/11/varnish-staus-after-restart.png 733w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-staus-after-restart-300x204.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-staus-after-restart-696x474.png 696w, https://www.osradar.com/wp-content/uploads/2019/11/varnish-staus-after-restart-617x420.png 617w" sizes="(max-width: 733px) 100vw, 733px" /></figure></div>



<p>Also make sure that Nginx/Apache server is configured as a back-end server for Varnish proxy.</p>



<pre class="wp-block-verse">sudo vi /etc/varnish/default.vcl</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="653" height="122" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/default-backend-server.png" alt="" class="wp-image-15610" srcset="https://www.osradar.com/wp-content/uploads/2019/11/default-backend-server.png 653w, https://www.osradar.com/wp-content/uploads/2019/11/default-backend-server-300x56.png 300w" sizes="(max-width: 653px) 100vw, 653px" /></figure></div>



<p>Look port<strong> 8080</strong> is configured on Apache/Nginx web server.</p>



<p>Your configuration will look like this for multiple back-ends,</p>



<pre class="wp-block-verse">backend default {<br>     .host = "127.0.0.1";<br>     .port = "8080";<br> }<br>backend java {<br>     .host = "127.0.0.1";<br>     .port = "8000";<br> } </pre>



<p>But we&#8217;ll need to tell Varnish to where send the difference URL using vcl_recv. For example our java application should handle URL beginning with <strong>/java/</strong></p>



<pre class="wp-block-verse">sub vcl_recv {<br>     if (req.url ~ "^/java/") {<br>         set req.backend_hint = java;<br>     } else {<br>         set req.backend_hint = default;<br>     }<br> }</pre>



<p>You can see more ones on using<a rel="noreferrer noopener" aria-label="You can see more ones on using Multiple backends. (opens in a new tab)" href="https://varnish-cache.org/docs/trunk/users-guide/vcl-backends.html" target="_blank"> Multiple backends.</a></p>



<h3><strong>Step 5: Testing Varnish Cache on Nginx/Apache</strong></h3>



<p>After all, verify Varnish Cache working by testing it with Apache/Nginx service with the curl command:</p>



<pre class="wp-block-verse">curl -I http://localhost</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="734" height="353" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/Curl-localhost.png" alt="" class="wp-image-15612" srcset="https://www.osradar.com/wp-content/uploads/2019/11/Curl-localhost.png 734w, https://www.osradar.com/wp-content/uploads/2019/11/Curl-localhost-300x144.png 300w, https://www.osradar.com/wp-content/uploads/2019/11/Curl-localhost-696x335.png 696w" sizes="(max-width: 734px) 100vw, 734px" /></figure></div>



<p>It will provide you HTTP header information.</p>



<p>If you run this command again, it will show you that <strong>Varnish Cached Response</strong> (Note that <strong>Age</strong> header):</p>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="653" height="248" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/curl-again.png" alt="" class="wp-image-15613" srcset="https://www.osradar.com/wp-content/uploads/2019/11/curl-again.png 653w, https://www.osradar.com/wp-content/uploads/2019/11/curl-again-300x114.png 300w" sizes="(max-width: 653px) 100vw, 653px" /></figure></div>



<p>This will work same for other valid domain names with DNS record set.</p>



<pre class="wp-block-verse">curl -I https://osradar.com</pre>



<div class="wp-block-image"><figure class="aligncenter"><img loading="lazy" width="526" height="115" src="//1723336065.rsc.cdn77.org/wp-content/uploads/2019/11/osradar.com_.png" alt="" class="wp-image-15614" srcset="https://www.osradar.com/wp-content/uploads/2019/11/osradar.com_.png 526w, https://www.osradar.com/wp-content/uploads/2019/11/osradar.com_-300x66.png 300w" sizes="(max-width: 526px) 100vw, 526px" /></figure></div>



<p>We&#8217;ve installed &amp; configured Varnish Cache on CentOS 8 / RHEL 8 for Nginx and Apache Web Server.</p>



<p>Visit the <a href="https://www.varnish-software.com/wiki/start/index.html">Varnish Getting Started </a>and <a href="https://varnish-cache.org/docs/trunk/users-guide/index.html#users-guide-index">The Varnish Users Guide</a> pages to learn more about configuring &amp; optimizing Varnish.</p>
<p>The post <a rel="nofollow" href="https://www.osradar.com/how-to-install-varnish-cache-6-for-apache-nginx-on-centos-rhel-8/">How to Install Varnish cache 6 for Apache/Nginx on Centos / RHEL 8</a> appeared first on <a rel="nofollow" href="https://www.osradar.com">Linux  Windows and android  Tutorials</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.osradar.com/how-to-install-varnish-cache-6-for-apache-nginx-on-centos-rhel-8/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
