Ondrej Sika

Nginx cross origin resource sharing (CORS)

18 May 2014

Example of nginx server configuration with CORS.

server {
    listen 80;
    server_name cdn.ondrejsika.com

    if ($request_method = 'OPTIONS') {
        return 200;
    }

    add_header 'Access-Control-Allow-Origin' 'http://ondrejsika.com';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Headers' 'Content-Type, Accept, X-Requested-With';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT, DELETE';

    location / {
        alias /var/cdn.ondrejsika.com/;
    } 
}

Source

Share on Facebook, Twitter, Google+, Linkedin

comments powered by Disqus

--