0

I would like to do something like this:

location / {

    if($http_x_my_header == 'some-value') {
        proxy_pass "https://a/";
    }
    # else
    proxy_pass "https://b/";

}

Because I know that using "IF" in NGINX can be kind of problematic: How would I solve this following "best practices"?

eventhorizon
  • 2,977
  • 8
  • 33
  • 57
  • 1
    Check this: https://github.com/openresty/lua-resty-core/blob/master/lib/ngx/balancer.md – un.def May 18 '21 at 12:24
  • 1
    This approach is not involving Lua and IMO the best one from many others https://stackoverflow.com/questions/59671623/conditionally-map-values-in-nginx-config – Alexander Altshuler May 19 '21 at 09:17
  • I am using the second approach now (defining a mapping variable) and it works quite well! THX! Maybe you could answer the question so I can mark it as the/my solution. I am also using a lua approach like linked above - but for a different scenario :-) – eventhorizon May 20 '21 at 13:54

0 Answers0