-1

Can I setup Varnish for one Subdomain and block it for all other Domains on my server?

Will this code work?

    backend magento244.example.com {
    .host = "magento244.example.com";
    .port = "8080";
    .first_byte_timeout = 600s;
    .probe = {
    .url = "/health_check.php";
        .timeout = 2s;
        .interval = 5s;
        .window = 10;
        .threshold = 5;
   }
}

if (req.http.host == 'www.example.com') {
    return (pass);
}
Oscar
  • 27
  • 1
  • 6

1 Answers1

0

The code you provided will bypass the cache for www.example.com requests.

Assuming you only want traffic to be handled for www.example.com and you want to block all other traffic, I'd use the following VCL code:

sub vcl_recv {
    // Block requests for other hosts
    if(req.http.Host != "www.example.com") {
        return(synth(403));
    }
    // The rest of your VCL code can go here
}

This code will return a 403 Forbidden status for all requests that are not for the www.example.com host.

If you have a different interpretation of blocking requests, please update your question and provide more context.

Thijs Feryn
  • 3,982
  • 1
  • 5
  • 10