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

Originally published at: https://www.cyberciti.biz/faq/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts/

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 (https://www.cyberciti.biz/faq/how-to-install-and-configure-varnish-cache-on-ubuntu-linux-16-04-lts/ ) and another tutorial (Use Varnish Cache to Boost Performance [Detailed Guide] ) 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 192.168.1.10:8080, run telnet and see if it connects:
    telnet 192.168.1.10 8080
  3. cd into /var/log/varnish/ and look for error logs. Another option is to run varnishlog command.