user2443795
user2443795

Reputation: 138

Amazon AWS + Varnish + varnish-devicedetect

Can somebody help setup this?

In my instance (RHEL), installed Varnish it work well. Then setup varnish-devicedetect,

 yum  list installed | grep varnish
 varnish.x86_64                        3.0.5-1.16.amzn1             @amzn-main
 varnish-libs.x86_64                   3.0.5-1.16.amzn1             @amzn-main
 varnish-release.noarch                4.0-3.el6                    installed

When I tried add any code example to defaul.vcl, Varnish fails to start. This code is OK:

 include "devicedetect.vcl";
 sub vcl_recv {
     call devicedetect;
 }

But after this Varnish fails to start:

 sub vcl_backend_response {
     if (bereq.http.X-UA-Device) {
         if (!beresp.http.Vary) { # no Vary at all
             set beresp.http.Vary = "X-UA-Device";
         } elsif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
             set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
         }
     }
     # comment this out if you don't want the client to know your classification
     set beresp.http.X-UA-Device = bereq.http.X-UA-Device;
 }

Tried, even empty:

 sub vcl_backend_response {

 }

Caused same problem. What I missed?

Upvotes: 1

Views: 180

Answers (2)

Ray Jennings
Ray Jennings

Reputation: 345

You could have found the error by trying to compile your vcl:

varnishd -C -f default.vcl (or whatever the path is to your vcl file)

This will tell you if your vcl has valid syntax or not - which will let varnish start without failure.

Upvotes: 1

user2443795
user2443795

Reputation: 138

It seems found answer: need use rules from Varnish ver. 3, used this set:

sub vcl_fetch {
    if (req.http.X-UA-Device) {
        if (!beresp.http.Vary) { # no Vary at all
            set beresp.http.Vary = "X-UA-Device";
        } elseif (beresp.http.Vary !~ "X-UA-Device") { # add to existing Vary
            set beresp.http.Vary = beresp.http.Vary + ", X-UA-Device";
        }
    }
    set beresp.http.X-UA-Device = req.http.X-UA-Device;
}
sub vcl_deliver {
    if ((req.http.X-UA-Device) && (resp.http.Vary)) {
        set resp.http.Vary = regsub(resp.http.Vary, "X-UA-Device", "User-Agent");
    }
}

Found here: https://www.varnish-cache.org/docs/3.0/tutorial/devicedetection.html

Upvotes: 1

Related Questions