Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Conditional not working?

$
0
0
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

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>