1. Background

    This rule prevents caching if the file extension ends with .css or .js and the http method is either GET or HEAD. Notice that we have to use variables to accomplish this behavior.

  2. Rule

  3. Regular Expression Visualization

  4. Resulting Nginx Configuration Block

        location ~ \.(?:css|js)$ {
        set $no_cache 0
        if ($http_method ~ (GET|HEAD)) {
        set $no_cache 1;
        }
        ...
        proxy_no_cache $no_cache;
        ...
        }