<?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 Archives - LinuxTuto</title>
	<atom:link href="https://www.linuxtuto.com/tag/varnish/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.linuxtuto.com/tag/varnish/</link>
	<description>Linux Sysadmin and DevOps blog</description>
	<lastBuildDate>Thu, 06 Apr 2023 13:00:03 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://www.linuxtuto.com/wp-content/uploads/2022/01/cropped-LT_faveicon-32x32.png</url>
	<title>Varnish Archives - LinuxTuto</title>
	<link>https://www.linuxtuto.com/tag/varnish/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">201456972</site>	<item>
		<title>How to Install Varnish with Nginx on AlmaLinux 9</title>
		<link>https://www.linuxtuto.com/how-to-install-varnish-with-nginx-on-almalinux-9/</link>
					<comments>https://www.linuxtuto.com/how-to-install-varnish-with-nginx-on-almalinux-9/#respond</comments>
		
		<dc:creator><![CDATA[LinuxTuto]]></dc:creator>
		<pubDate>Thu, 06 Apr 2023 13:00:03 +0000</pubDate>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[AlmaLinux]]></category>
		<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Varnish]]></category>
		<guid isPermaLink="false">https://www.linuxtuto.com/?p=1247</guid>

					<description><![CDATA[<p>Varnish is a popular open-source web application accelerator, also known as a caching HTTP reverse proxy, that is used to speed up dynamic web content...</p>
<p>The post <a href="https://www.linuxtuto.com/how-to-install-varnish-with-nginx-on-almalinux-9/">How to Install Varnish with Nginx on AlmaLinux 9</a> appeared first on <a href="https://www.linuxtuto.com">LinuxTuto</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Varnish is a popular open-source web application accelerator, also known as a caching HTTP reverse proxy, that is used to speed up dynamic web content delivery. It caches frequently accessed content and serves it directly from memory, reducing the load on the application servers and reducing the response time for users.</p>
<p>Varnish sits between the client and the web server and acts as an intermediary. When a user requests a web page, Varnish checks if the page is already in its cache. If it is, Varnish serves the page directly from its cache, without having to request it from the web server. If the page is not in the cache, Varnish requests it from the web server and caches it for future use.</p>
<p>Varnish also allows users to configure cache policies and rules to optimize caching behavior, and provides tools for monitoring and analyzing cache performance. It is commonly used by high-traffic websites to improve their performance and scalability.</p>
<p>In this tutorial, we will show you how to install  and configure <code>Varnish</code> with <code>Nginx</code> on AlmaLinux 9.</p>
<h2><span class="has-inline-color has-vivid-purple-color">Step 1: Update Operating System</span></h2>
<p>Update your <strong>AlmaLinux 9</strong> operating system to make sure all existing packages are up to date:</p>
<pre><code># dnf update</code></pre>
<p>Also, install the EPEL package manager to allow <code>Varnish</code> dependencies to be installed:</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers language-plain" data-lang="Plain Text"><code class=" language-plain"># dnf install epel-release </code></pre>
</div>
<h2><span class="has-inline-color has-vivid-purple-color">Step 2: Install Nginx</span></h2>
<p>You can install Nginx via <code>dnf</code> package manager by executing the following command.</p>
<pre><code># dnf install nginx</code></pre>
<p>Nginx does not start automatically when it is installed. You can start the Nginx service and configure it to run on startup by entering the following commands:</p>
<pre><code># systemctl start nginx
# systemctl enable nginx</code></pre>
<p>Verify the status of the <code>Nginx</code> service using <code>systemctl status</code> command:</p>
<pre><code># systemctl status nginx</code></pre>
<p>Output:</p>
<pre><code><span style="color: #00ff00;">●</span> nginx.service - The nginx HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
    Drop-In: /usr/lib/systemd/system/nginx.service.d
             └─php-fpm.conf
     Active: <span style="color: #00ff00;">active (running)</span>
   Main PID: 1720 (nginx)
      Tasks: 2 (limit: 5740)
     Memory: 2.3M
        CPU: 28ms
     CGroup: /system.slice/nginx.service
             ├─1720 "nginx: master process /usr/sbin/nginx"
             └─1721 "nginx: worker process"

</code></pre>
<p>If <code>firewalld</code> is enabled consider allowing <code>HTTP</code> and <code>HTTPS</code> services:</p>
<pre><code>$ sudo firewall-cmd --permanent --add-service={http,https}
$ sudo firewall-cmd --reload</code></pre>
<p>Now you need to configure Nginx to work with Varnish Cache.</p>
<p>Open the Nginx config file <strong>/etc/nginx/nginx.conf</strong> :</p>
<pre><code> # nano /etc/nginx/nginx.conf</code></pre>
<p>Search for the <mark>Listen</mark> line and change it to <strong>8080</strong>:</p>
<pre><code>.....   
    server {
        listen       <strong><span style="color: #ff0000;">8080</span></strong>;
        listen       [::]:<strong><span style="color: #ff0000;">8080</span></strong>;
        server_name  _;
        root         /usr/share/nginx/html;
 .....</code></pre>
<p>Save and close the file. Then restart the Nginx service to apply the changes:</p>
<pre><code># systemctl restart nginx</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Step 3: Install Varnish 7</span></h2>
<p>First disable the <code>Varnish</code> service from the <code>dnf</code> package manager:</p>
<pre><code># dnf module disable varnish</code></pre>
<p>By default, the latest version of Varnish is not available on the AlmaLinux 9 base repository.</p>
<p>So you need to run the following command to add the latest <code>Varnish</code> repository to your system:</p>
<pre><code>curl -s https://packagecloud.io/install/repositories/varnishcache/varnish73/script.rpm.sh | bash</code></pre>
<p>After the repository is added, install Varnish using the following command:</p>
<pre><code># dnf install varnish</code></pre>
<p>Check the installed version with the following command:</p>
<pre><code># varnishd -V</code></pre>
<p>Output:</p>
<pre><code>varnishd (varnish-7.3.0 revision 84d79120b6d17b11819a663a93160743f293e63f)
Copyright (c) 2006 Verdens Gang AS
Copyright (c) 2006-2023 Varnish Software</code></pre>
<p>Now start and enable <code>Varnish</code> (to start automatically upon system boot):</p>
<pre><code># systemctl start varnish
# systemctl enable varnish</code></pre>
<p>Verify the status using the following command:</p>
<pre><code># systemctl status varnish</code></pre>
<pre><code>● varnish.service - Varnish Cache, a high-performance HTTP accelerator
Loaded: loaded (/usr/lib/systemd/system/varnish.service; enabled; vendor preset: disabled)
Active: active (running)
Main PID: 4266 (varnishd)
Tasks: 217
Memory: 113.4M
CPU: 2.074s
CGroup: /system.slice/varnish.service
├─4266 /usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -f /etc/varnish/default.vcl -P /run/varnish/varnishd.pid -p feature=+http2 -s malloc&gt;
└─4280 /usr/sbin/varnishd -a :6081 -a localhost:8443,PROXY -f /etc/varnish/default.vcl -P /run/varnish/varnishd.pid -p feature=+http2 -s malloc&gt;</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Step 4: Configure Varnish Cache</span></h2>
<p>The default <code>Varnish</code> listening port is 6081. Now we need to configure <code>Varnish</code> to listen on port 80.</p>
<p>You can do it by editing <code>/usr/lib/systemd/system/varnish.service</code> file:</p>
<pre><code># nano /usr/lib/systemd/system/varnish.service</code></pre>
<p>Add the configuration to change the port <strong>6081</strong> to <strong>80</strong> as shown below:</p>
<pre><code>...
ExecStart=/usr/sbin/varnishd \
-a :<span style="color: #ff0000;"><strong>80</strong></span> \
-a localhost:8443,PROXY \
-f /etc/varnish/default.vcl \
-P %t/%N/varnishd.pid \
-p feature=+http2 \
-s malloc,256m
ExecReload=/usr/sbin/varnishreload
...</code></pre>
<p>After the changes, restart the <code>Varnish</code> service for the changes to take effect.</p>
<pre><code># systemctl daemon-reload
# sudo systemctl restart varnish</code></pre>
<h2><span class="has-inline-color has-vivid-purple-color">Step 5: Test Varnish Cache</span></h2>
<p>Test if <code>Varnish</code> cache is enabled and working with the Nginx service using the <code>curl</code> command:</p>
<pre><code># curl -I http://your-IP-address</code></pre>
<p>Output:</p>
<pre><code>HTTP/1.1 200 OK
Server: nginx/1.20.1
Date: Thu, 06 Apr 2023 11:22:04 GMT
Content-Type: text/html
Content-Length: 4681
Last-Modified: Sat, 09 Oct 2021 17:49:21 GMT
ETag: "6161d621-1249"
<span style="color: #ff0000;">X-Varnish: 2</span>
Age: 0
<span style="color: #ff0000;">Via: 1.1 192.168.1.150 (Varnish/7.3)</span>
Accept-Ranges: bytes
Connection: keep-alive</code></pre>
<p>This means that your Varnish Cashe is active and running on your server.</p>
<h2><span class="has-inline-color has-vivid-purple-color">Comments and Conclusion</span></h2>
<p>In the tutorial, you have learned how to install and configure <code>Varnish</code> on AlmaLinux 9.</p>
<p>For additional help or useful information, you can check <a href="https://varnish-cache.org/docs/" target="_blank" rel="noopener">the official Varnish website</a>.</p>
<p>The post <a href="https://www.linuxtuto.com/how-to-install-varnish-with-nginx-on-almalinux-9/">How to Install Varnish with Nginx on AlmaLinux 9</a> appeared first on <a href="https://www.linuxtuto.com">LinuxTuto</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.linuxtuto.com/how-to-install-varnish-with-nginx-on-almalinux-9/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1247</post-id>	</item>
	</channel>
</rss>
