Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / self_route.vcl
Last active February 28, 2024 12:56
Self routing Varnish Cache cluster example
# Self routing cluster example
vcl 4.0;
import directors;
backend node1 {
.host = "node1.example.com";
.port = "80";
}
@rezan
rezan / cvmfs.vcl
Last active February 22, 2024 14:01
Varnish VCL for CVMFS (CernVM-FS)
#
# CVMFS VCL (v1.3)
#
# Tested with CVMFS 2.11 and Varnish Cache 6/7
#
vcl 4.1;
backend cvmfs_origin {
.host = "hostname.org";
@rezan
rezan / s3.vcl
Last active July 6, 2023 13:02
Varnish AWS S3 Gateway VCL
#
# Varnish AWS S3 Gateway VCL
#
# Allows global read (GET, HEAD) and ACL protected writes (POST, PUT, DELETE).
# When writing, pass in Content-Type and Content-MD5, both are optional.
#
# Params:
#
# %BUCKET% - S3 bucket name, S3 host may be regional
# %ACCESS_ID% - IAM access ID for bucket
@rezan
rezan / csp_nonce.vtc
Created August 13, 2018 19:12
Generate CSP nonces for Javascript
varnishtest "Generate CSP nonces for Javascript"
server s1 {
rxreq
txresp -hdr "Content-Type: text/html" -body {
<html>
<script>
var a=1;
</script>
</html>
@rezan
rezan / no_args.c
Created October 18, 2021 16:51
Valid C program, no errors (-Wall -Wextra -Wpedantic -Werror)
#include <stdio.h>
void test();
int main()
{
printf("no args\n");
test();
return 0;
}
@rezan
rezan / states.vcl
Created March 30, 2021 13:23
VHA6 req.url rewrite hook
#
# VHA6 req.url rewrite hook
#
# File location: /etc/varnish/vha6/hooks/states.vcl
#
import std;
sub vha6_hook_init {
}
@rezan
rezan / miss_302.vcl
Created February 19, 2021 14:30
Varnish VCL - cache misses get an instant 302 response and are fetched in the background
#
# Cache misses get an instant 302 response and are fetched in the background
# (Include this file in your VCL)
#
vcl 4.1;
import std;
import synthbackend;
import vha;
@rezan
rezan / probe_proxy.vcl
Last active December 1, 2020 18:40
Probe Proxy implementation
#
# Probe Proxy v1.0
#
import directors;
import kvstore;
import probe_proxy;
import std;
acl probe_proxy_local {
@rezan
rezan / body_restart.vtc
Created September 21, 2020 16:47
req.body and restarts
varnishtest "req.body and restarts"
server s1 -repeat 4 {
rxreq
txresp -bodylen 1000
} -start
varnish v1 -vcl+backend {
import std;
@rezan
rezan / S00001.vtc
Created July 6, 2020 18:30
varnishscoreboard vcl_recv
varnishtest "varnishscoreboard vcl_recv"
barrier b1 sock 2
barrier b2 sock 2
server s1 {
} -start
varnish v1 -cliok "param.set thread_pool_track on" -vcl+backend {