Question

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

Subscribe
Share

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

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.

Accepted Answer

Hi,

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: https://packagecloud.io/varnishcache/varnish41/install#manual-deb replacing trusty with xenial (16.04)

  2. Configure the backend like so:

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

Once you’ve done that, you will have Varnish configured to listen locally on port 6081 and proxy requests to 127.0.0.1:8080. Now, you’ll need to (1) move your existing nginx configuration to 127.0.0.1:8080, 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 http://127.0.0.1:6081;. Finally, go into your existing virtual host, remove the SSL bits, and configure it to listen on 127.0.0.1:8080 like so:

server {
    listen 127.0.0.1:80;
    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