Nginx 1.18 - sub_filter + if statement

Ahmed Sajid ahmed.sajid at securekey.com
Thu Sep 10 22:45:31 UTC 2020


Hi All,

Not sure if this question has been answered before. The only evidence I could find was a StackExchange question https://serverfault.com/questions/774750/use-of-sub-filter-in-if-block-under-nginx-config with no answer.

Here's what I'm trying to accomplish:

  *   If the request is coming from a specific using agent, set override var to 1
  *   under location block if override is 1 only then apply sub_filter

Here's the snippet:

    if ($http_user_agent = 'HTTPie/1.0.3') {
        set $override_content 1;
    }

    location / {
        proxy_set_header   Accept-Encoding "";
        proxy_pass  $upstream_endpoint;
        if ($override_content = 1) {
            sub_filter 'abcabcabcabc' 'xyzxyzxyzxyz';
            sub_filter_types 'application/json';
            sub_filter_once off;
        }
    }

I get error nginx: [emerg] "sub_filter" directive is not allowed here

When I remove the if block, there's no complain or error and Nginx runs fine.

Any idea why this doesn't work?

Best Regards,
Ahmed.


This email and any attachments are for the sole use of the intended recipients and may be privileged, confidential or otherwise exempt from disclosure under law. Any distribution, printing or other use by anyone other than the intended recipient is prohibited. If you are not an intended recipient, please contact the sender immediately, and permanently delete this email and its attachments.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20200910/47256880/attachment.htm>


More information about the nginx mailing list