I'm using the following:
set $cors FALSE;
if ($http_origin ~* (http://example.com|http://dev.example.com:8000|http://dev2.example.com)) {
set $cors TRUE;
}
if ($request_method = 'OPTIONS') {
set $cors $cors$request_method;
}
if ($cors = 'TRUE') {
add_header 'Access-Test' "$cors";
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'POST, OPTIONS';
add_header 'Access-Control-Max-Age' '1728000';
}
if ($cors = 'TRUEOPTIONS') {
add_header 'Access-Test' "$cors";
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, X-Prototype-Version';
add_header 'Access-Control-Max-Age' '1728000';
add_header 'Content-Type' 'text/plain';
}
The problem I'm having is that the conditionals ($cors = 'TRUE') and ($cors = 'TRUEOPTIONS') don't appear to evaluate. If I remove those statements, just so that the headers are sent with every request, I see that the $cors and $http_origin variables are set correctly. If those conditionals are in place, the headers are not sent at all.
I'm using nginx version 1.2.9.
Thanks
set $cors FALSE;
if ($http_origin ~* (http://example.com|http://dev.example.com:8000|http://dev2.example.com)) {
set $cors TRUE;
}
if ($request_method = 'OPTIONS') {
set $cors $cors$request_method;
}
if ($cors = 'TRUE') {
add_header 'Access-Test' "$cors";
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'POST, OPTIONS';
add_header 'Access-Control-Max-Age' '1728000';
}
if ($cors = 'TRUEOPTIONS') {
add_header 'Access-Test' "$cors";
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'X-Requested-With, X-Prototype-Version';
add_header 'Access-Control-Max-Age' '1728000';
add_header 'Content-Type' 'text/plain';
}
The problem I'm having is that the conditionals ($cors = 'TRUE') and ($cors = 'TRUEOPTIONS') don't appear to evaluate. If I remove those statements, just so that the headers are sent with every request, I see that the $cors and $http_origin variables are set correctly. If those conditionals are in place, the headers are not sent at all.
I'm using nginx version 1.2.9.
Thanks