• rod

    Hi Jeff,
    please, could you explain the same for centos?. I tried to follow your steps and translate for centos but I have not succeeded. thank you very much in advance.

    • jeffreifman

      Rod, sorry – I am focusing on Ubuntu.

    • http://www.facebook.com/monahan.matthewjames Matthew Monahan

      For centOS, the default config is in /etc/sysconfig/varnish, while the default.vcl goes right in the same place, /etc/varnish/default.vcl. You’ll have to change your Apache port to 8080 in /etc/httpd/conf.d/vhost.conf (assuming you set it up that way) and in /etc/httpd/conf/httpd.conf (in this one, by default NameVirtualHost is all the way at the end of the file, so make sure to scroll all the way through). After this it should work, just restart httpd and varnish.

      • jeffreifman

        Matthew – thx for offering this!

      • Matt Florence

        I’m not using apache with my node/ghost setup. But I thought I’d also point out for others that on amazon ec2 ami linux the varnish config is also in /etc/sysconfig/varnish instead of /etc/default/varnish. This post was very helpful along with http://we.je/using-varnish-not-nginx-to-run-ghost/ to get things up and running. Thanks!

  • CostaQuanto

    I’m getting this error massage when I restart Varnish

    root@ubuntu:/etc/varnish# /etc/init.d/varnish restart

    * Stopping HTTP accelerator varnishd [fail]

    * Starting HTTP accelerator varnishd [fail]

    Message from VCC-compiler:

    Syntax error at

    (‘input’ Line 25 Pos 1)

    _unique

    #——

    Running VCC-compiler failed, exit 1

    VCL compilation failed

    root@ubuntu:/etc/varnish#

    • jeffreifman

      Costa, as I noted above “Note: you may get VCL errors when you attempt to restart Varnish if you do not properly maintain line breaks when pasting.” Go back thru your file and edit it carefully line by line. Or, if you changed any of the VCL code, you might have broken something.

      • CostaQuanto

        OK, thanks for letting me know, I’ll try it out and let you know about it

    • Luis

      I have exactly the same error. Please help!

      • jeffreifman

        Luis – see my note below – you likely mis-pasted extra line breaks into your VCL file.

    • http://www.adornomedia.com/ David H

      There is accidental linebreak at the end of line 24. The word _unique should be on line 24.

      • jeffreifman

        Thx David – I’ve identified and fixed 3 such line breaks. basically I think gist was creating line breaks on my long comments

        • http://www.mornin.org/ Joseph Mornin

          I had the same problem. Lines 25 and 44 in default.vcl were broken into two lines. You can fix this by joining these lines with the lines directly after.

    • MK

      After Varnishing, the site went weird and all the other pages e.g. login are going to 404 :-(

  • Jacob

    Hello,

    FYI – when I disabled the default site ‘sudo a2dissite 000-default’ I was no longer able to static files like css and js since the path went from MYSITE.com/wordpress/ to just MYSITE.com. Likewise, the admin section didn’t work due to all the redirects for /wordpress/.

    To fix this I reinstated the default site ‘sudo a2ensite 000-default’ to get access to the admin site again and then went to Settings > General and changed both the WordPress Address and the Site Address, removing the /wordpress from both. Then, go ‘sudo a2dissite 000-default’ and you’re back in business.

    this was a minor trip up but I thought someone else might have the same problem so I wanted to post it here.

    thanks for this tutorial, it’s wicked awesome.

  • Paul

    “Replace the Varnish VCL configuration with the file below (copy and paste). Note: you may get VCL errors when you attempt to restart Varnish if you do not properly maintain line breaks when pasting.”

    Which file below? I don’t see it in Safari or Chrome.

  • Paul

    Here is a link to the default.vcl file example that isn’t showing up on this page:

    https://gist.github.com/reifman/4651531

    There are a couple of line breaks in the code. The compiler will tell you which ones. Once you edit and fix the default.vcl correctly. It will work. I think I did notice a performance boost. Will have to see.

    • http://jeffreifman.com/consulting Jeff Reifman

      Thanks Paul – this is fixed again. WordPress has an annoying habit of stripping out script tags in visual editing mode.

  • Go4

    Thank you for excellent article! Unfortunately, I have many problems with Varnish (not compatible with Jetpack etc), I have installed Varnish the way you described in your blog. Now, I would like to deactivate Varnish. Which steps would you recommend to disable or remove Varnish? Thank you!

  • Patrick K. Johnson Jr.

    Jeff, thanks. Post helped. Took some time with the technical tweaking of switching form Virtualmin configuration to get everything to work, but in the end it all worked very well like a champ. So, if anyone is using “Virtualmin/Webmin” and need some help, please let me know. I will answer as much as I can to assist.

  • Justin J

    Great Post Jeff, Thank You! I am however having one issue that is difficult to reproduce. I am getting the following error

    Error 503 Service Unavailable
    Service Unavailable
    Guru Meditation:
    XID: 1051325111
    ________________________
    Varnish cache server

    This occurs mainly when hitting the backend and more seldomly on the frontend. I see that Go4 has an issue with Varnish and Jetpack, could this be the cause of my error?

    • http://jeffreifman.com/consulting Jeff Reifman

      I’ve seen this when the AWS instance is out of memory or slow. Add a swap file to your micro instance or experiment with a different instance size. I’m not sure that this is the cause though.

  • Tim Crandley

    Jeff – Amazing post! Any advice on setting up the VCL to handle multiple sites? I have a single server with 2 separate domains (example.com and othersite.com) both with WordPress installations located in /var/www/example and /var/www/othersite. I can access both until I install varnish, but one I follow your instruction I can’t get to either. I’ve been trolling the varnish sites and found the following code to add to the VCL, but I don’t know if it will work:

    if (req.http.host) {
    hash_data(req.http.host);
    }
    else {
    hash_data(server.ip);

    }

    Any ideas? Thanks a ton!

  • Matt

    Jeff,

    Thank you for putting the time into crafting these instructions.

    I have several vhost conf files on my Apache server. When I followed the instructions above, it broke all the other (non-WordPress) sites on the server. To fix it, I switched my /etc/apache2/ports.conf file back to 80 from 8080, and put the lines

    NameVirtualHost *:8080
    Listen 8080

    at the top of my WordPress site’s conf file. Everything seems to be working now, but I can’t tell if my WP site is being Varnished. Is this the recommended solution, or is there a better way?

  • Aba Cadabra

    I can’t (re-)start Varnish because the VCC compiler stops on the line breaks. How to insert the default.vcl config file correctly? I tried putting the options on line, removing the the slashes, copy/paste it to text editor and then to terminal. Nothing really makes a difference. Anybody can tell me how to copy/paste it correctly?