Skip to content

Instantly share code, notes, and snippets.

@rezan
rezan / lets_encrypt.vcl
Created October 19, 2018 00:52
Lets Encrypt certbot challenge VCL with backend failover
# Lets Encrypt certbot challenge VCL
backend certbot {
.host = "127.0.0.1";
.port = "888";
}
sub vcl_recv {
unset req.http.X-lets-certbot;
if (req.url ~ "^/\.well-known/acme-challenge/" && !req.restarts) {
@rezan
rezan / json_http.vtc
Created September 28, 2018 15:51
Forward JSON req and resp body to another service (VCP 4.1)
varnishtest "Test JSON forwarding (4.1)"
server s1 {
rxreq
txresp -body {
{
"key":"respvalue",
"key2":23,
"2": {
"nested":"goal"
@rezan
rezan / json_nested.vtc
Created September 26, 2018 13:43
Test JSON response body parsing with nesting
varnishtest "Test JSON response body parsing with nesting"
server s1 {
rxreq
txresp -body {
{
"key":"value",
"key2":23,
"2": {
"nested":"goal"
@rezan
rezan / json.vtc
Created September 25, 2018 15:23
Test JSON response body parsing
varnishtest "Test JSON response body parsing"
server s1 {
rxreq
txresp -body {
{
"key":"value",
"key2":23
}
}
@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 / hit_miss.vcl
Last active July 20, 2018 13:57
hit_miss.vcl for Varnish 6.0
# hit_miss.vcl for Varnish 6.0
vcl 4.0;
# What are we, hit, miss, or pass?
sub vcl_recv {
set req.http.X-status = "NONE";
}
@rezan
rezan / aggregate.vtc
Created July 3, 2018 19:48
Use aggregate.vcl to get the true response time in VCL for slow responses
varnishtest "Test using Varnish to aggregate headers and body"
server s1 {
rxreq
expect req.url == "/1"
txresp -nolen -hdr "Content-Length: 3"
delay 3
send "abc"
rxreq
@rezan
rezan / aggregate.vcl
Created July 3, 2018 19:48
Aggregate response headers and body into a single response block
vcl 4.0;
# If you set req.http.X-aggregate = "true", Varnish will aggregate
# the headers and response body into a single response block
# Point this back to Varnish
#backend loop {
# .host = "127.0.0.1";
# .port = "80";
#}
@rezan
rezan / magento.vcl
Created April 26, 2018 20:25
Magento 1.x VCL configuration
// Magento 1.x VCL configuration
vcl 4.0;
import cookieplus;
import edgestash;
import kvstore;
import xbody;
sub vcl_init
@rezan
rezan / vary_kvstore.vcl
Created March 23, 2018 15:48
Vary + kvstore
vcl 4.0;
import kvstore;
# https://docs.varnish-software.com/varnish-cache-plus/vmods/kvstore-4/
sub vcl_init
{
kvstore.init(0, 25000);
}