<?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>gj |</title>
	<atom:link href="https://blog.gaiterjones.com/category/magento2/varnish-fpc/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/category/magento2/varnish-fpc/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Tue, 16 Feb 2021 11:41:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>How to Configure Varnish for Magento 2</title>
		<link>https://blog.gaiterjones.com/how-to-configure-varnish-for-magento-2/</link>
					<comments>https://blog.gaiterjones.com/how-to-configure-varnish-for-magento-2/#respond</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Tue, 16 Feb 2021 11:28:22 +0000</pubDate>
				<category><![CDATA[Magento2]]></category>
		<category><![CDATA[Varnish FPC]]></category>
		<guid isPermaLink="false">https://blog.gaiterjones.com/?p=2430</guid>

					<description><![CDATA[Varnish and Magento 2 go together like Strawberries and Cream &#8211; you just cannot have one without the other. Recently I got really confused about the correct way to configure...<a class="more-link" href="https://blog.gaiterjones.com/how-to-configure-varnish-for-magento-2/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>Varnish and Magento 2 go together like <code>Strawberries</code> and <code>Cream</code> &#8211; you just cannot have one without the other.</p>
<p>Recently I got really confused about the correct way to configure Varnish for Magento 2, so for me and anyone else confused about the configuration here is the definitive guide to configuring Varnish for Magento 2.</p>
<h1>The Definitive Guide to Configuring Varnish for Magento 2</h1>
<p>To configure Varnish you need to know:</p>
<ul>
<li>Varnish server name</li>
<li>Varnish listener TCP port &#8211; defaults to 6081</li>
<li>Magento content server name</li>
<li>Magento content server TCP port</li>
</ul>
<p>If you are working with a single host the server name for Varnish and Magento will be localhost (127.0.0.1), if you are working in a Docker environment the server name for Varnish and Magento will be the container names of the Varnish and Magento web/content server services.</p>
<p>There are two areas in Magento where you must configure Varnish settings:</p>
<ol>
<li>Magento Core Config : <code>app/etc/env.php</code></li>
<li>Magento admin <code>Stores -> Configuration -> System -> Full Page Cache</code></li>
</ol>
<h2>Core Config</h2>
<p>The core config for Varnish in <code>app/etc/env.php</code> looks something like this:</p>
<pre class="brush: php; title: ; notranslate">
    'http_cache_hosts' =&gt; &#x5B;
        &#x5B;
            'host' =&gt; 'varnish_server_hostname',
            'port' =&gt; '6081'
        ]
    ],
</pre>
<ul>
<li><strong>HOST</strong>=hostname / ip address of Varnish server</li>
<li><strong>PORT</strong>=TCP listener port of Varnish server</li>
</ul>
<p>You can configure these settings from the command line using:</p>
<p><code>php bin/magento setup:config:set --http-cache-hosts=varnish_server_hostname:6081</code></p>
<h2>Admin Config</h2>
<p>The admin config for Varnish in <code>Stores -> Configuration -> System -> Full Page Cache</code> looks something like this:</p>
<figure id="attachment_2432" aria-describedby="caption-attachment-2432" style="width: 550px" class="wp-caption aligncenter"><img fetchpriority="high" decoding="async" src="https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2-620x340.jpg" alt="Magento 2 Varnish FPC Admin Configuration" width="550" height="302" class="size-large wp-image-2432" srcset="https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2-620x340.jpg 620w, https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2-440x241.jpg 440w, https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2-768x421.jpg 768w, https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2-760x417.jpg 760w, https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2-550x302.jpg 550w, https://blog.gaiterjones.com/wp-content/uploads/2021/02/varnish2.jpg 800w" sizes="(max-width: 550px) 100vw, 550px" /><figcaption id="caption-attachment-2432" class="wp-caption-text">Magento 2 Varnish FPC Admin Configuration</figcaption></figure>
<ul>
<li><strong>ACCESS LIST</strong>=hostname / ip address of Magento content server/s</li>
<li><strong>BACKEND HOST</strong>=hostname / ip address of Magento content server/s</li>
<li><strong>BACKEND PORT</strong>=TCP listener port of Magento content server</li>
<li><strong>EXPORT CONFIGURATION</strong>=Click here to export a the Varnish VCL file</li>
</ul>
<p><strong>Note that the Varnish Configuration section settings here are only used to generate the Varnish VCL file.</strong></p>
<p>If you are using Docker set the acl purge list in the Varnish VCL to all Docker private networks.</p>
<pre class="brush: plain; title: ; notranslate">
# purge set to docker nets
# 172.0.0.0/12 192.168.0.0/16
acl purge {
    &quot;172.16.0.0&quot;/12;
    &quot;192.168.0.0&quot;/16;
}
</pre>
<h2>Troubleshooting</h2>
<p>You can verify your Varnish configuration with <a href="https://github.com/netz98/n98-magerun2" rel="noopener" target="_blank">n98-magerun2</a>. Use the command:</p>
<p><code>n98-magerun2.phar config:show | grep full_page_cache</code></p>
<p>You should see something like the following where magento2_php-apache_1is the hostname of your Magento 2 content server and backend_port is the tcp port of the content (Magento) server</p>
<pre class="brush: plain; title: ; notranslate">
system/full_page_cache/caching_application - 2
system/full_page_cache/varnish/access_list - magento2_php-apache_1
system/full_page_cache/varnish/backend_host - magento2_php-apache_1
system/full_page_cache/varnish/backend_port - 8080
system/full_page_cache/varnish/grace_period - 300
</pre>
<p><strong>Don’t get the ports mixed up :</strong></p>
<ul>
<li>By default Varnish is configured to listen for incoming external client http requests on TCP 6081.</li>
<li>The backend_port configured in admin is only used for the vcl config generation.</li>
<li>The env.php http_cache_hosts port is the port used to communicate with varnish.</li>
</ul>
<p>To confirm your Varnish cache is working examine the headers returned by your Varnish server when browsing Magento frontend pages. You can also inspect the headers using curl</p>
<p><code>curl -I -H "host: magento2.gaiterjones.com" 127.0.0.1:80</code></p>
<pre class="brush: plain; title: ; notranslate">
X-Varnish: 762904605
Age: 0
X-Magento-Cache-Debug: HIT
Pragma: no-cache
Expires: -1
Cache-Control: no-store
</pre>
<p>Here we can see the X-Magento-Cache-Debug header showing a cache hit. Note &#8211; this header will be disabled in production mode.</p>
<p><em>Remember that Varnish has no support for TLS connections over HTTPS.</em> To use an encrypted TLS connection to Magento 2 with Varnish FPC you need to use a frontend proxy such as NGINX.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/how-to-configure-varnish-for-magento-2/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
