title: proxy_pass based on headers without using if condition
body: <p>I'm looking for a way to reroute all requests that have set an account-id in the HTTP header <code>Account-ID</code> with the last two digits (of a ten digit number) <code>00</code> to <code>05</code> (to touch only 5% of the total traffic). In addition, if a request has set the HTTP header <code>Server-A</code>, that request should be forwarded to that server regardless of the set account-id. Otherwise and by default, all traffic should be handled by server-b. My current location-rule looks like this:</p>
  
  <pre><code>location /rest/accounts/ {
    if ( $http_account_id ~ '([\d]{8})(0[0-4])') {
      proxy_pass http://server-a.company.com;
    }
  
    if ( $http_server_a = true) {
      proxy_pass http://server-a.company.com;
    }
  
    proxy_pass http://server-b.company.com;
  }
  </code></pre>
  
  <p>As I read in the official documents <a href="https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/" rel="noreferrer">here</a>, <code>if</code> is considered <em>evil</em>. </p>
  
  <p>Is there a better solution for my approach which isn't considered <em>evil</em>? </p>