How to Install and configure Varnish in Ubuntu 16.04

I already install NGINX, PHP-FPM, MariaDB and Wordpress in Ubuntu 16.04. Also, I have Let’s Encrypt SSL.

Now I want to install Varnish and configure it in the backend of NGINX since I used SSL all request from 443.

My current configuration is

User ==> Cloudflare ==> NGINX

how to configure varnish in following way

User ==> Cloudflare ==> NGINX ==>Varnish

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Kamal Nasser
DigitalOcean Employee
DigitalOcean Employee badge
February 20, 2018
Accepted Answer


Since Varnish does not support SSL termination, you will need to configure nginx to do so, forward requests to Varnish, which would then forward them back to nginx over HTTP. Follow this tutorial with a few adjustments:

  1. Use the following instructions to install Varnish: replacing trusty with xenial (16.04)

  2. Configure the backend like so:

backend default {
    .host = "";
    .port = "8080";
  1. Replace DAEMON_OPTS="-a :6081 \ with ``DAEMON_OPTS="-a `.

Once you’ve done that, you will have Varnish configured to listen locally on port 6081 and proxy requests to Now, you’ll need to (1) move your existing nginx configuration to, and (2) configure a new virtual host that handles SSL termination.

(2) is also part of the tutorial that I linked. Make sure you set proxy_pass to;. Finally, go into your existing virtual host, remove the SSL bits, and configure it to listen on like so:

server {
    server_name your_domain_name;

Restart nginx and you should be able to browse to https://yourdomain with everything working properly.

Thank you, I already figure it out few days ago !! Anyway thanks.

Is there any minimum requirement for running varnish?

I have deoplet of $5 i.e. 1 vcpu, 1GB RAM and 25 GB storage.

I run already 3 wordpress site here.

I don’t want any caching plugin to use. Is varnish will be good?

What is your opinion about server side caching vs cache plugin.

Please explain

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel