How to install and configure Varnish cache on Ubuntu Linux 16.04 LTS

Originally published at:

How do I install Varnish Cache server to improve the performance of my existing Apache web server especially caching dynamic content on Ubuntu Linux 16.04 LTS server?

I am running a Cakephp based website on a Debian server. I am trying to configure varnish on my website, but getting 503 error. I tried to follow your tutorial ( ) and another tutorial ( ) as well, but in both cases I am getting 503 error. I cannot figure what is causing this issue. Maybe something else on my server or app is conflicting with varnish?

This error means varnish failed to connect to the backend server running a Cakephp based app. Try:

  1. Can you see requests from Varnish in your backend webserver log file?
  2. From varnish server one can use nc/telenet to see if you can connect to backend. Say backend is running on, run telnet and see if it connects:
    telnet 8080
  3. cd into /var/log/varnish/ and look for error logs. Another option is to run varnishlog command.