<html><head></head><body><div style="color:black;font-size:14px">Hi Guillaume,<br></div><div style="color: black;font-size: 14px;">I'l give it a try.<br></div><div style="color: black;font-size: 14px;"><br></div><div style="color: black;font-size: 14px;">Thank you very much<br></div><div style="color: black;font-size: 14px;">Riccardo</div><div style="color:black;font-size:14px" class="signature"><br></div><div><br></div><div>12/07/2023, 17:27 Guillaume Quintard ha scritto:<br></div><blockquote style="border-left: 2px solid #a8a8a8;margin-left: 0px;padding-left: 10px;margin-top: 0.5rem;"><div class="qbox-body"><div dir="ltr"><div>Hi Riccardo,<br></div><div><br></div><div>You are right, I assumed that the tags were uuids of some sorts and welp, they're not.<br></div><div><br></div><div>The best way would be to ask magento to fix it by including a hash of the host or something in each tag, but that's probably not going to happen any time soon.<br></div><div><br></div><div>The next best way is to teach Varnish to be a bit more selective when banning. This is done in three steps.<br></div><div><br></div><div>First, we are going to mark the backend response with the host it comes from (maybe Magento2 already does it in some form, in which case you can use that header instead):<br></div><div><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace"># add this to the beginning of vcl_backend_response</span></span><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace">sub vcl_backend_response {</span></span><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace"> set beresp.http.x-host = bereq.http.host;</span></span><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace"> ...</span></span><br></div><div><br></div><div>Then, we change the ban() calls to only apply to the responses with the right x-host headers:<br></div><div><span style=""><span class="font" style="font-family:monospace"></span></span><br></div><div><span style=""><span class="font" style="font-family:monospace"> if (req.http.X-Magento-Tags-Pattern) {<br> ban("obj.http.x-host == + req.http.host + " && obj.http.X-Magento-Tags ~ " + req.http.X-Magento-Tags-Pattern);<br> }<br> if (req.http.X-Pool) {<br> ban(</span></span><span style=""><span class="font" style="font-family:monospace">"obj.http.x-host == + req.http.host + </span></span><span style=""><span class="font" style="font-family:monospace">"&& obj.http.X-Pool ~ " + req.http.X-Pool);<br> }</span></span></div><div><span style=""><span class="font" style="font-family:monospace"></span></span><br></div><div>Lastly, we don't need the x-host header to be exposed to the client, so we strip it at the beginning of vcl_deliver:<br></div><div><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace">sub vcl_deliver {</span></span><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace"> unset resp.http.x-host;</span></span><br></div><div style="margin-left:40px"><span style=""><span class="font" style="font-family:monospace"> ...</span></span><br></div><div><br></div><div>disclaimer: This test is completely untested, and it's early in the morning, so you probably shouldn't trust me too much and you should test this before throwing it in prod.<br></div><div><br></div><div>Technically, you *could* use req.http.host directly, but you don't want to because of the ban-lurker and its performance implications.<br></div><div><br></div><div>Hope this helps.<br></div><div><br></div><div><div><div data-smartmail="gmail_signature" class="gmail_signature" dir="ltr"><div dir="ltr"><div>-- <br></div><div>Guillaume Quintard<br></div></div></div></div><div><br></div></div></div><div><br></div><div class="gmail_quote"><div class="gmail_attr" dir="ltr">On Wed, Jul 12, 2023 at 4:15 AM Riccardo Brunetti <<a href="mailto:riccardo.brunetti@host.it">riccardo.brunetti@host.it</a>> wrote:<br></div><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote"><div><div style="color:black;font-size:14px">Hello Guillaume.<br></div><div style="color:black;font-size:14px">Thanks for your answer.<br></div><div style="color:black;font-size:14px">The VCL is actually almost identical to that you mentioned in the link (I'm attaching it without references to names and IP anyway)<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">What somehow worries me is that, if I understand, the ban is performed according to some "X-Magento-Tags".<br></div><div style="color:black;font-size:14px">Now, if I look at the output of varnishlog and search for "*Tags*", what I get is:<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">1) while navigating the site:<br></div><blockquote style="border-left:2px solid rgb(168,168,168);padding-left:10px;margin-top:0.5rem"><div style="color:black;font-size:14px">....<br></div><div style="color:black;font-size:14px">- RespHeader X-Magento-Tags: NAVIGATIONPRO_MENU_2<br></div><div style="color:black;font-size:14px">- RespUnset X-Magento-Tags: NAVIGATIONPRO_MENU_2<br></div><div style="color:black;font-size:14px">- RespHeader X-Magento-Tags: store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_footer_payments,cms_b_header_block_custom_links,cms_b_main_bottom_newsletter,cms_b_main_bottom_strenghts,cms_b<br></div><div style="color:black;font-size:14px">- RespUnset X-Magento-Tags: store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_footer_payments,cms_b_header_block_custom_links,cms_b_main_bottom_newsletter,cms_b_main_bottom_strenghts,cms_b<br></div><div style="color:black;font-size:14px">- BerespHeader X-Magento-Tags: cat_c_595,cat_c_p_595,store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_footer_payments,cms_b_header_block_custom_links,cms_b_main_bottom_newsletter,cms_b_main_<br></div><div style="color:black;font-size:14px">- BerespHeader X-Magento-Tags: NAVIGATIONPRO_MENU_2<br></div><div style="color:black;font-size:14px">- RespHeader X-Magento-Tags: NAVIGATIONPRO_MENU_2<br></div><div style="color:black;font-size:14px">- RespUnset X-Magento-Tags: NAVIGATIONPRO_MENU_2<br></div><div style="color:black;font-size:14px">- RespHeader X-Magento-Tags: cat_c_595,cat_c_p_595,store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_footer_payments,cms_b_header_block_custom_links,cms_b_main_bottom_newsletter,cms_b_main_<br></div><div style="color:black;font-size:14px">- RespUnset X-Magento-Tags: cat_c_595,cat_c_p_595,store,cms_b,gdpr_c,theme_editor_backend_css_block,cms_b_header_cms_links,cms_b_argento_scroll_up,cms_b_footer_cms_content,cms_b_footer_payments,cms_b_header_block_custom_links,cms_b_main_bottom_newsletter,cms_b_main_<br></div><div style="color:black;font-size:14px">.....<br></div></blockquote><div style="color:black;font-size:14px">2) when performing a purge (php bin/magento c:f):<br></div><blockquote style="border-left:2px solid rgb(168,168,168);padding-left:10px;margin-top:0.5rem"><div style="color:black;font-size:14px">...<br></div><div style="color:black;font-size:14px">- ReqHeader X-Magento-Tags-Pattern: .*<br></div><div style="color:black;font-size:14px">...<br></div></blockquote><div style="color:black;font-size:14px">In both cases I can't see any specific reference to that particular site.<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">Thanks again.<br></div><div style="color:black;font-size:14px">Riccardo<br></div><div><br></div><div>11/07/2023, 17:09 Guillaume Quintard ha scritto:<br></div><blockquote style="border-left:2px solid rgb(168,168,168);margin-left:0px;padding-left:10px;margin-top:0.5rem"><div><div dir="ltr"><div>Hi Ricardo,<br></div><div><br></div><div>Having your VCL (even anonymized) would help here, otherwise debugging is pretty hard. For the moment, I'm going to assume you are using a variation of <a href="https://github.com/magento/magento2/blob/13e54e1b28a5d590ab885bd4df9f58877b549052/app/code/Magento/PageCache/etc/varnish6.vcl">https://github.com/magento/magento2/blob/13e54e1b28a5d590ab885bd4df9f58877b549052/app/code/Magento/PageCache/etc/varnish6.vcl</a> and deal in generalities.<br></div><div><br></div><div>The way that vcl invalidates content is through bans: <a href="https://github.com/magento/magento2/blob/13e54e1b28a5d590ab885bd4df9f58877b549052/app/code/Magento/PageCache/etc/varnish6.vcl#L30-L47">https://github.com/magento/magento2/blob/13e54e1b28a5d590ab885bd4df9f58877b549052/app/code/Magento/PageCache/etc/varnish6.vcl#L30-L47</a> which doesn't need the host header, it's just uses unique tags pushed by the backend in response headers.<br></div><div>If it was using the actual purge mechanism, then modifying the host should be sufficient because purge acts on the object found in the cache (and if you can get a hit, you can get purged).<br></div><div><br></div><div>Here's a good primer on invalidation: <a href="https://docs.varnish-software.com/tutorials/cache-invalidation/">https://docs.varnish-software.com/tutorials/cache-invalidation/</a><br></div><div><br></div><div>Kind regards,<br></div><div><br></div><div><br></div><div><br></div><div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>-- <br></div><div>Guillaume Quintard<br></div></div></div></div><div><br></div></div></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 11, 2023 at 4:14 AM Riccardo Brunetti <<a href="mailto:riccardo.brunetti@host.it">riccardo.brunetti@host.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0.5rem 0px 0px 0.8ex;border-left:2px solid rgb(168,168,168);padding-left:10px"><div><div style="color:black;font-size:14px">Hello.<br></div><div style="color:black;font-size:14px">I'm new to varnish and I have a question concerning how to manage multiple sites using the same varnish cache frontend.<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">More specifically, I need to setup a single varnish cache server for two different Magento2 sites.<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">Looking around I found that it is possible to manage different backends using something like:<br></div><div style="color:black;font-size:14px"><br></div><blockquote style="border-left:2px solid rgb(168,168,168);padding-left:10px;margin-top:0.5rem"><div style="color:black;font-size:14px">if (req.http.host == "somesite") {<br></div><div style="color:black;font-size:14px"> set req.backend_hint = somebackend;<br></div><div style="color:black;font-size:14px"> }<br></div></blockquote><div style="color:black;font-size:14px">Now, I have two different Magento2 sites and, using the above expression, I can handle the two different backends.<br></div><div style="color:black;font-size:14px">The problem is that I can't understand how to handle the PURGE/BAN of the two independently.<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">As far as I understand from the .vcl file that Magento2 itself produces there is nothing inside the "purge" section that specifies which resources must be purged.<br></div><div style="color:black;font-size:14px">It seems to me that is site A performs a purge, than also the cache of site B resources will be cleaned.<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">Can you help me with this or point me to some example or tutorials?<br></div><div style="color:black;font-size:14px"><br></div><div style="color:black;font-size:14px">Thanks a lot<br></div><div style="color:black;font-size:14px">Riccardo <br></div></div><div>_______________________________________________<br></div><div>varnish-misc mailing list<br></div><div><a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br></div><div><a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a><br></div></blockquote></div></div></blockquote><div style="color:black;font-size:14px"><br></div></div></blockquote></div></div></blockquote><div style="color: black;font-size: 14px;"><br></div></body></html>