Ignore query string with Nginx caching proxy



Published: 2019-03-27 17:51:36 +0000
Categories: NGinx,

Language

NGinx

Description

Query strings in URLs give incredible flexibility, but are also an easy way for users to bypass your cache by appending random arguments (known as a cachebuster).

This documentation details how to adjust the cache key on a Nginx cachine reverse proxy, either to completely ignore the query string, or to only honour specific ones. If you're only serving static files then you'll likely want to ignore query strings entirely.

Snippet

# Ignore query string entirely
proxy_cache_key "$scheme$host$uri";

# Only include query string args foo and bar
proxy_cache_key "$scheme$host$uri$is_args$arg_foo&$arg_bar";

Keywords

nginx, caching, query string, ignore, proxy,

Latest Posts


Copyright © 2019 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk and snippets.6zdgh5a5e6zpchdz.onion