Setting a custom header based on another upstream/sent header

Reinis Rozitis r at roze.lv
Thu Aug 22 12:26:12 UTC 2019


> Is this expected behaviour? Could there be another way to do this?

'if' (the rewrite module) is executed in early stages when $sent_* variables are not available that’s why the regex doesn't match.

What you could do is use 'map' instead:
(http://nginx.org/en/docs/http/ngx_http_map_module.html )


map $sent_http_link $IS_WORDPRESS  {
   ~*.*wp-json.* "true";
    default "false";
}

And then:

add_header                    X-Is-WordPress $IS_WORDPRESS;

rr



More information about the nginx mailing list