Im trying to find what is the relation between rewrite statement in nginx location block and set variable statement inside location block. Why im asking is because of different behaviour in below 2 cases
what does not work- getting http 500 as url is not set - when set is after rewrite statement*
location ~ ^/offer/ {
log_by_lua_file lua/datadog/api_latency.lua;
proxy_pass $url;
proxy_read_timeout 60;
rewrite ^((?U).*)(/?)$ $1 break;
set $location_name offer;
set $url https://example.com;
}
What works - when set is before rewrite statement
location ~ ^/offer/ {
log_by_lua_file lua/datadog/api_latency.lua;
proxy_pass $url;
proxy_read_timeout 60;
set $url https://example.com;
rewrite ^((?U).*)(/?)$ $1 break;
set $location_name offer;
}
In the nginx debug logs i can see that set variable being executed in working case but not in non working case. I have searched in nginx documentation if there is any relation - best i can get is that both of these are executed in rewrite phase but no other info regarding cause of this behaviour.
Any idea why this is happening?