monsur / enable-cors.org

Advocacy for CORS
http://enable-cors.org/
212 stars 99 forks source link

Nginx cors example not functioning #95

Closed spyrospph closed 9 years ago

spyrospph commented 9 years ago

Hi,

The example on the enable-cors.org site fails within the if blocks here:

http://enable-cors.org/server_nginx.html

Using nginx >1.4.6 thebelow example fails with a 404. location / { if ($request_method = 'GET') { set $cors "${cors}get";
}

try_files $uri $uri/ /index.php?$args; }

The above code breaks within the if and never reaches the try_files statement. Seems like a set directive within an if statement causes nginx to break. In fact any directive inside an if statement triggers http://wiki.nginx.org/IfIsEvil

thoughtless commented 9 years ago

They should be using map instead. See http://serverfault.com/questions/674900/nginx-if-statement-inside-location-returns-404

monsur commented 9 years ago

I've updated the site with the answer from Thoughtless. Thanks!