2020-07-30

Varnish Cache

 30 Jul 2020  Snippets

Varnish Cache

Installation
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
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
Automated Cache Cleaning
0 0 * * 0 systemctl restart varnish >/dev/null 2>&1
Backends

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

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

Server Test:

varnishlog
 
varnishtop -i BereqURL

Client Test:

curl -H 'Host: domain.com' http://123.456.78.90 -I
NGINX Proxy
sudo apt install nginx

Configuration for 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;
        }
}
Ports

Varnish & NGINX ports:

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

Copyright © Paramdeo Singh. Made with ☕️ in Guyana. All Rights Reserved.

Last Site Build on Tue, 30 Nov 2021 19:17:38 -0500

1MB Club Badge

Paramdeo Singh Guyana

Riding the wave of consciousness in this treacherous mortal sea.

Technology Design Strategy Literature Personal Blogs