2020-07-30

Varnish Cache CLI

 30 Jul 2020  Gists

Varnish Cache CLI

Install Varnish:

sudo apt update && sudo apt upgrade -y; dpkg-reconfigure tzdata

sudo apt install curl gnupg apt-transport-https -y

curl -s https://packagecloud.io/install/repositories/varnishcache/varnish64/script.deb.sh | sudo bash

sudo apt install varnish=6.4.0-1~bionic

Configure Varnish defaults:

nano /etc/varnish/default.vcl

nano /lib/systemd/system/varnish.service

ExecStart=/usr/sbin/varnishd -a :80 -f /etc/varnish/default.vcl -s malloc,1280m

systemctl daemon-reload && systemctl restart varnish

Set weekly cron to clear cache:

0 0 * * 0 systemctl restart varnish >/dev/null 2>&1

Mark backend as manually healthy or automatic (via probe):

varnishadm backend.set_health lemp0 healthy
varnishadm backend.set_health lemp0 auto

Server Test: varnishlog or varnishtop -i BereqURL

Client Test: curl -H 'Host: domain.com' http://123.456.78.90 -I

Setup NGINX:

sudo apt install nginx

Configure NGINX as Varnish Proxy:

server {
        listen 443 ssl;

        server_name domain.com www.domain.com;
        ssl_certificate /etc/nginx/cert/domain.com.pem;
        ssl_certificate_key /etc/nginx/cert/domain.com.key;

        location / {
            proxy_pass http://127.0.0.1:80;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto https;
            proxy_set_header X-Forwarded-Port 443;
            proxy_set_header Host $host;
        }
}

Test Varnish & NGINX ports:

lsof -i :80 | grep LISTEN
lsof -i :443 | grep LISTEN
Webmentions & Comments

Copyright © Paramdeo Singh. Built with Jekyll and ☕️ in Guyana. All Rights Reserved.

Last Site Build on Fri, 18 Jun 2021 13:00:57 -0400

1MB Club Badge

Paramdeo Singh Guyana

Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs