Skip to content

Instantly share code, notes, and snippets.

@itslukej
Created April 14, 2023 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itslukej/2f1c2f7242d3f4d1fde86a619788d0c8 to your computer and use it in GitHub Desktop.
Save itslukej/2f1c2f7242d3f4d1fde86a619788d0c8 to your computer and use it in GitHub Desktop.
# Caches movie covers, tv covers and other media
# Replace <YOUR PLEX TOKEN> with a random plex token
# docker-compose.yml
# varnish:
# image: "varnish:fresh"
# network_mode: "host"
# environment:
# VARNISH_SIZE: 2G
# VARNISH_HTTP_PORT: 32500
# tmpfs:
# - /var/lib/varnish/example:exec
# volumes:
# - /etc/varnish/default.vcl:/etc/varnish/default.vcl:ro
# network_mode: "host"
vcl 4.1;
import cookie;
backend default {
.host = "127.0.0.1";
.port = "32400";
}
sub vcl_recv {
if (req.url ~ "^\/.*\/:\/transcode.*") {
set req.url = regsuball(req.url, "X-Plex-Token%3D([-_A-z0-9+()%.]+)", "X-Plex-Token%3D<YOUR PLEX TOKEN>");
set req.url = regsuball(req.url, "X-Plex-Token=([-_A-z0-9+()%.]+)", "X-Plex-Token=<YOUR PLEX TOKEN>");
} else {
return (pass);
}
}
sub vcl_deliver {
if (obj.hits > 0) { # Add debug header to see if it's a HIT/MISS and the number of hits, disable when not needed
set resp.http.X-Cache = "HIT";
} else {
set resp.http.X-Cache = "MISS";
}
# Please note that obj.hits behaviour changed in 4.0, now it counts per objecthead, not per object
# and obj.hits may not be reset in some cases where bans are in use. See bug 1492 for details.
# So take hits with a grain of salt
set resp.http.X-Cache-Hits = obj.hits;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment