How can I use varnish cache with nginx SSL termination for my SSL-Only (Https only) website? I use ubuntu 18.04 and I am currently running a wordpress site on my server.

  • i aint know for what you want to use vanish, if you want to use caching use nginx directly
    – djdomi
    Aug 21, 2019 at 17:34
  • Varnish caching is more faster compared to nginx caching Aug 21, 2019 at 18:03

1 Answer 1


Sofar I add the complete way

mkdir /var/cache/nginx/cache
chown nginx:nginx /var/cache/nginx/cache

Now Edit nginx.conf below the http section

###New cache settings as default
proxy_cache_path /var/cache/nginx/cache levels=1:2 keys_zone=hd_cache:10m max_size=10g inactive=2d use_temp_path=off;
proxy_cache_methods GET HEAD POST;
proxy_cache_valid 200 302 3d;
proxy_cache_valid 404      1m;

edit /etc/nginx/sites-avaible/yoursite.com

#http to https redirect
server {
        server_name yoursite.com *.yoursite.com;
        listen 80;
        return 301 https://$host$request_uri;

#https server
server {
        proxy_read_timeout 3600;
        listen 443 ssl http2;
        server_name yoursite.com *.yoursite.com;

#a special location in case don't cache this file can be deleted
location updater/serversettings.xml {
          expires -1;
          add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0';

                #The root/rest will be redirected
                location / {
                        proxy_cache             hd_cache;
                        proxy_set_header        X-Cache-Status $upstream_cache_status;
                        proxy_cache_valid       200 1w;
                        proxy_pass    ;
                        proxy_set_header        Host $http_host;
                        proxy_buffers           16 8m;
                        proxy_buffer_size       2m;
                        gzip on;
                        gzip_vary          on;
                        gzip_comp_level    9;
                        gzip_proxied       any;
    #SSL Cert section, as we require ssl, using certbot LetsEncrypt
    ssl_certificate /etc/letsencrypt/live/yoursite.com-0001/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/yoursite.com-0001/privkey.pem; # managed by Certbot

Now Enable this site.

ln -s /etc/nginx/sites-avaible/yoursite.com /etc/nginx/sites-enabled/yoursite.com

and run

service Nginx reload

This Setup works fine for a WordPress site, I encounter a page speed counter of 95+

  • @RahulBiswas you can safely remove vanish, as it only doubles the interaction. see my answer to speed up
    – djdomi
    Aug 22, 2019 at 8:51
  • 1
    Yeah....i have removed Varnish now... Aug 22, 2019 at 15:05
  • and if the config helped you, i would be hsppy about an upvote and accept as answer
    – djdomi
    Aug 22, 2019 at 17:13
  • 1
    My upvotes won't be public before 15 reps...but answer def. accepted! Aug 23, 2019 at 5:04
  • thanks, that setup i also use for any other sites i host and it pumping the stuff out, even i ran for each site an contsiner on my proxmox host
    – djdomi
    Aug 23, 2019 at 5:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.