Kelvin
Kelvin

Reputation: 8963

Different Varnish VCL based on URL

I have Magento installation in a subfolder and a WordPress site. How can I use the same Varnish installation for two different CMS?

I have prepared the following default.vcl file code example, but not sure if I am moving in the right direction. Thanks

vcl 4.0;
if (req.url ~ "^/path/to/magento/") {
include "magento.vcl";
 } elseif (req.url ~ "^/path/to/wordpress/") {
include "wordpress.vcl";
}

P.S. My Varnish version is 4.0

Upvotes: 0

Views: 170

Answers (1)

Thijs Feryn
Thijs Feryn

Reputation: 4808

Before I continue, please be ware of the fact that Varnish 4 is end-of-life. Any bug or error you encounter will not be fixed and can result in unexpected behavior. The best way forward is by upgrading to Varnish 6.

That being said, you are definitely moving in the right direction. But please make sure the included logic is put inside a subroutine.

Your example code will typically live inside sub vcl_recv {}. If you have logic that belongs in other subroutines (like sub vcl_backend_response {} for example), please make sure you include that logic as well.

Upvotes: 0

Related Questions