<% is_first = true %> vcl 4.0; # generated varnish config: <%= ENVIRONMENT %> # local test: <%= LOCAL_TEST_MODE ? 'ENABLED' : 'DISABLED' %> sub vcl_recv { std.log("pre varnish log info '<%= domain.name %>':" + req.http.host); if (req.http.host ~ "<%= domain.name %>$") { std.log("varnish log info '<%= domain.name %>':" + req.http.host); <% domain.subdomains.each_pair do |subdomain_name, subdomain| %> <%= is_first ? '' : 'else ' %>if (req.http.host ~ "^<%= subdomain.name %>.<%= domain.name %>$") { std.log("subdomain identified '<%= subdomain.name %>.<%= domain.name %>':" + req.http.host + " url: " + req.url ); <% %w(direct dynamic).each do |type| %> <% subdomain[type].each_pair do |url, page| %> if (req.url ~ "^<%= prepare_url url %>") { std.log("page identified '<%= subdomain.name %>.<%= domain.name %>' Page:'<%= url %>':" + req.url); <% if 'direct'.eql? type %> set req.backend_hint = <%= page.director %>.backend(); <% unless page.plugin_url.nil? %>set req.url = "<%= page.plugin_url %>";<% end %> <% else %> set req.backend_hint = core_backend_director.backend(); set req.url = "/template/page?req_url=" + req.url + "&req_host=" + req.http.host + "<%= template_url_for(domain, page) %>"; <% end %> return (hash); } <% end %> <% end %> <% subdomain.get_redirects.each_pair do |src, target| %> if (req.url ~ "<%= src %>") { std.log("redirect identified '<%= subdomain.name %>.<%= domain.name %>' src:'<%= src %>':" + req.url); set req.http.Location = "<%= target %>"; return (synth(750, "Permanently moved")); } <% end %> } <% is_first = false %> <% end %> <%= is_first ? '' : 'else' %> { # Redirect to default std.log("varnish log info 'redirect to default':" + req.url); set req.http.Location = "http://<%= default_subdomain_for(domain) %>.<%= domain.name %>" + req.url; return (synth(750, "Permanently moved")); } } } sub vcl_deliver { if (req.http.host ~ "<%= domain.name %>$") { # What to do? } }