Welcome! Log In Create A New Profile

Advanced

Nginx 1.18 - sub_filter + if statement

Ahmed Sajid
September 10, 2020 06:46PM
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.
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx 1.18 - sub_filter + if statement

Ahmed Sajid September 10, 2020 06:46PM

Re: Nginx 1.18 - sub_filter + if statement

J.R. September 10, 2020 07:40PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 174
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready