Skip to content

Instantly share code, notes, and snippets.

@sega-yarkin
Created September 29, 2017 14:01
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 sega-yarkin/c26bc5fbf8c6afc1fae9dedd8f90c138 to your computer and use it in GitHub Desktop.
Save sega-yarkin/c26bc5fbf8c6afc1fae9dedd8f90c138 to your computer and use it in GitHub Desktop.
Varnish VCL for caching RabbitMQ Management plugin (3.5.7)
vcl 4.0;
# RabbitMQ management console.
backend default { .host = "127.0.0.1"; .port = "15673"; }
sub vcl_recv {
# We only deal with GET and HEAD
if( req.method!="GET" && req.method!="HEAD" ) {
return (pass);
}
# Remove random part from ejs requests.
if( req.url ~ "\.ejs\?" ) {
set req.url = regsub( req.url, "\.ejs\?.*", "\.ejs" );
}
return (hash);
}
sub vcl_hash {
hash_data( req.url );
if( req.http.authorization ) {
hash_data( req.http.authorization );
}
return (lookup);
}
# For debug purpose.
sub vcl_hit { set req.http.X-Cache = "hit"; }
sub vcl_miss { set req.http.X-Cache = "miss"; }
sub vcl_pass { set req.http.X-Cache = "pass"; }
sub vcl_backend_response {
# We want to cache everything.
unset beresp.http.cache-control;
# Set TTL for caching ang grace time for cases backend unavailability.
set beresp.ttl = 15s;
set beresp.grace = 15s;
# Set big TTL for static resources.
if( bereq.url ~ "\.(png|js|ejs)" ) {
set beresp.ttl = 7d;
}
# Compress it
set beresp.do_gzip = true;
}
sub vcl_deliver {
if( req.http.X-Cache ) {
set resp.http.X-Cache = req.http.X-Cache;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment