monsur / enable-cors.org

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

CORS on nginx #98

Closed joshpangell closed 9 years ago

joshpangell commented 9 years ago

Your article on enabling CORS for nginx does not work in all cases. I found a much better, and much more too the point, solution. Here is the post that worked for me: https://michielkalkman.com/snippets/nginx-cors-open-configuration.html

That is a very in-depth approach when settings different options for different request types. Really all that is needed is this:

location / {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}