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 © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter