Allowing the etag directive within if in location
Maxim Dounin
mdounin at mdounin.ru
Sat Nov 26 17:37:37 UTC 2022
Hello!
On Sun, Nov 27, 2022 at 01:01:54AM +0800, Danila Vershinin wrote:
> Hi,
>
> For our purposes, we need to be able to turn off etag under specific
> conditions, e.g.:
>
> location / {
> if ($condition) {
> etag off;
> }
> }
>
> However, this syntax is invalid because this directive doesn't include
> the NGX_HTTP_LIF_CONF flag.
>
> We added that flag. Then recompiled NGINX. So now:
>
> * the syntax is accepted by NGINX
> * at runtime it works as desired
>
> Are there any potential problems with this approach? Performance or
> otherwise?
The generic issue with the "if" directive within a location
context is that it creates a separate configuration, and therefore
works in a counter-intuitive way in many cases (including being
counter-intuitive for developers, which results in various bugs),
see IfIsEvil wiki article for the details. Due to this, no new
directives are allowed to work in the if-in-location context.
Other than that, it probably should work fine assuming it works
for you now and you are ok to maintain the patch yourself.
A more portable solution might be to use
map $condition $etag {
default $sent_http_etag;
1 "";
}
add_header ETag $etag;
to conditionally remove the ETag header.
--
Maxim Dounin
http://mdounin.ru/
More information about the nginx-devel
mailing list