The NGINX conf bellow is not working on nginx -t
:
location ~ ^/ETC[0-9](?:\.json|\.(?<ext>csv))?/?$ {
if ($ext) {
set $extOpt '&csv=1';
proxy_set_header Accept 'text/csv'; # BUG HERE!
}
rewrite ^/ETC1 /rpc/etc?q=v1$extOpt; break;
rewrite ^/ETC[2-9] /rpc/etc?q=other$extOpt; break;
proxy_pass http://localhost:3002;
}
nginx: [emerg] "proxy_set_header" directive is not allowed here in /etc/nginx/...:17
nginx: configuration file /etc/nginx/nginx.conf test failed
I not see where the problem (see e. g. nginx/wiki)... Well, if the if
is not valid, there are a way to express conditional proxy_set_header
?
NOTES
Not make sense because when using direct
proxy_set_header Accept 'text/csv';
instead it in theif ($ext)
block, it works fine.It is similar but not a duplicate of this question/answer.