Welcome! Log In Create A New Profile

Advanced

Conditional not working?

Posted by chengjih 
Conditional not working?
June 26, 2013 09:17AM
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
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 144
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready