I face a strange issue with Nginx. This is a minimal config that reproduce the error:
server {
server_name mydomain.com;
listen 111.111.111.111:80;
root /some/path;
set $some_var $sent_http_content_type;
add_header "X-Debug" $sent_http_content_type;
}
In this case X-Debug
header is never shown in the response. But, if I comment this line:
set $some_var $sent_http_content_type;
everything works. It seems very strange to me because this line doesn't reassign the $sent_http_content_type
var, but only reads.
It looks like it belongs to $sent_http_
variables only.
I also tried "${sent_http_content_type}"
instead of $sent_http_content_type
with the same result.
more_set_headers
directive doesn't fix this.
Why does Nginx behave like this? Is this a bug?
Edit:
The example I have provided is just the simpest case where $sent_http_
vars desappear. In fact I want to do something like this:
if ($sent_http_access_control_allow_origin ~ "^(https?)://([^/]+)") {
set $new_cors http://$1.$2.proxy.mydomain.com;
}
more_set_headers "Access-Control-Allow-Origin: $new_cors";
I write a proxy server and I need to replace Access-Control-Allow-Origin
response header, because otherwise proxied sites don't work as expected.
In the above example if
condition (in server
section) never yields true
, even if there is such header and it fits my regular expression.
Can this be fixed? Appreciate your help!
if
directive also executed too early for you purpose.$upstream_http_*
variables.