Ignore query string with Nginx caching proxy (NGinx)

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.

Details

  • Language: NGinx

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";