User login

A couple VCL changes when upgrading to Varnish 3

The error messages Varnish provides are very informative.

tail -f /var/log/varnish/current

2014-03-02_03:52:40.47449 --------------------########-----------------------
2014-03-02_03:52:40.47449
2014-03-02_03:52:40.47450 Running VCC-compiler failed, exit 1
2014-03-02_03:52:40.47474
2014-03-02_03:52:40.47476 VCL compilation failed
2014-03-02_03:52:41.49353 Message from VCC-compiler:
2014-03-02_03:52:41.49356 Unknown variable 'req.hash'
2014-03-02_03:52:41.49360 At: ('/etc/varnish/example-includes/device-detect/device-detect.vcl' Line 61 Pos 21)
2014-03-02_03:52:41.49361 set req.hash += req.http.X-Device;

This change was clearly documented, and made in a few places:
https://www.varnish-cache.org/docs/3.0/installation/upgrade.html#req-hash-is-replaced-with-hash-data

So changed:

# Add the device to the hash (if its a mobile device)
sub vcl_hash {
        if (req.http.X-Device ~ "^mobile") {
                set req.hash += req.http.X-Device;
        }
}

to:

# Add the device to the hash (if its a mobile device)
sub vcl_hash {
        if (req.http.X-Device ~ "^mobile") {
                hash_data(req.http.X-Device);         
        }
}

Note: If you get the error "Unknown variable 'hash_data'" be sure you haven't left "set" before hash_data.

Also had to make similar changes to (and where you will be more likely to) our /etc/varnish/sites/example.vcl

The other error was "Expected ';' got 'obj.status'" and i couldn't
figure it out, so i removed the whole custom error message function that had it. (Same approach taken here.)

Searched words: 
varnish3 req.hash varnish Unknown variable 'hash_data' varnish

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.