nginx, why auth_request cannot be used in if section nginx, why auth_request cannot be used in if section nginx nginx

nginx, why auth_request cannot be used in if section


I did something like this today. Came to this solution:

location /api/books {    if ($request_method = POST) {        rewrite .* /_api/books last;    }    proxy_pass http://bookservice;}location /_api/books {    rewrite .* /api/books break;    auth_request /api/auth;    proxy_pass http://bookservice;    internal;}

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html

Would be much nicer with an if, but I don't know why it isn't allowed. However "if" is discouraged by nginx (https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/).