I have read https://www.nginx.com/resources/wiki/start/topics/depth/ifisevil/
I want to check if my rails application has already added a header (Access-Control-Allow-Origin
) and if it hasn't then add the header.
The examples here have tried to explain the behaviour of if
condition in nginx.conf http://agentzh.blogspot.in/2011/03/how-nginx-location-if-works.html
But I have not understood it. One of the question I have is what is meant when they say a directive or phase directive?
I have tried some things myself. Like:
location / {
add_header My-outer-header '*';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
if($sent_http_access_control_allow_origin != /*){
add_header My-inner-header '**';
}
}
Here when the if condition is met, only My-inner-header
is set and not the My-outer-header
.
But when I do:
location / {
add_header My-outer-header '*';
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
set $a 1;
if($a == 1){
add_header My-inner-header '**';
}
}
Here $a variable is set to 1 but only the My-inner-header
is set again and not the My-outer-header
.
I want to check and ensure if the instructions like proxy_set_header
are getting executed or not.