0

I have several Magento 2 instances under the same domain. For example, www.mydomain.com/magento1 and www.mydomain.com/magento2.

I am trying to set up Varnish against these Magento sites. However, how can I set up multiple backends if the sites are essentially using the same hostname? So, this example I've found for handling multiple backends, won't work for me.

 backend example1 {
     .host = "backend.example1.com";
     .port = "8080";
 }
 backend example2 {
      .host = "backend.example2.com";
      .port = "8080";
 }

Thanks in advance,

1
  • Even if from a vcl point of view, you could setup fancy regex to cache based on url, setting a backend usually require unique hostname. Since i presume your not in production with Magento running in a subfolder, i suggest you to move each magento to subdomain, eg www.mydomain.com/mag1 --> mag1.mydomain.com
    – x86fantini
    Sep 19 '16 at 11:27
0

In the vcl_recv() subrutine you can change the backend depending on the URI, for example this works in Varnish 4:

sub vcl_recv {
    if (req.url ~ "^(?i)/magento1") {
        set req.backend_hint = example1;
    }
    if (req.url ~ "^(?i)/magento2") {
        set req.backend_hint = example2;
    }
}
0

Just define the backends with IP address instead of hostname. Or use some in-house hostname for those machines along with the real hostnames.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.