Skip to content

Instantly share code, notes, and snippets.

@lukegalea
Forked from michiel/cors-nginx.conf
Last active January 1, 2016 05:49

Revisions

  1. lukegalea revised this gist Dec 23, 2013. 1 changed file with 15 additions and 6 deletions.
    21 changes: 15 additions & 6 deletions cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -12,13 +12,13 @@ location / {
    #

    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';

    #
    # Custom headers and headers various browsers *should* be OK with but aren't
    #

    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    add_header 'Access-Control-Allow-Headers' 'accept,authorization,origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    #
    # Tell client that this pre-flight info is valid for 20 days
    @@ -35,17 +35,26 @@ location / {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'accept,authorization,origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    }

    if ($request_method = 'GET') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'accept,authorization,origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    }

    if ($request_method = 'PUT') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'accept,authorization,origin,DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    }

  2. @michiel michiel revised this gist Sep 13, 2012. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ location / {

    if ($request_method = 'OPTIONS') {

    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Origin' '*';

    #
    # Om nom nom cookies
    @@ -28,12 +28,12 @@ location / {
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;

    return 200;
    return 204;
    }

    if ($request_method = 'POST') {

    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    @@ -42,7 +42,7 @@ location / {

    if ($request_method = 'GET') {

    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
  3. Michiel Kalkman revised this gist Jul 6, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ location / {

    if ($request_method = 'OPTIONS') {

    add_header 'Access-Control-Allow-Origin' 'http://10.0.0.20/';
    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';

    #
    # Om nom nom cookies
  4. Michiel Kalkman revised this gist Jul 6, 2011. 1 changed file with 38 additions and 24 deletions.
    62 changes: 38 additions & 24 deletions cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,38 +1,52 @@
    #
    # Wide-open CORS config for nginx
    #
    location / {

    location / {
    if ($request_method = 'OPTIONS') {

    if ($request_method = 'OPTIONS') {
    add_header 'Access-Control-Allow-Origin' 'http://10.0.0.20/';

    #
    # Om nom nom cookies
    #

    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';

    #
    # Custom headers and headers various browsers *should* be OK with but aren't
    #

    return 200;
    }
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    #
    # Tell client that this pre-flight info is valid for 20 days
    #

    if ($request_method = 'POST') {
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;

    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    return 200;
    }

    }
    if ($request_method = 'POST') {

    if ($request_method = 'GET') {
    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    }

    }
    if ($request_method = 'GET') {

    }
    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    }

    }
  5. Michiel Kalkman revised this gist Jul 6, 2011. 1 changed file with 25 additions and 26 deletions.
    51 changes: 25 additions & 26 deletions cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -2,38 +2,37 @@
    # Wide-open CORS config for nginx
    #

    location / {
    location / {

    if ($request_method = 'OPTIONS') {
    if ($request_method = 'OPTIONS') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;
    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;

    return 200;
    }
    return 200;
    }

    if ($request_method = 'POST') {
    if ($request_method = 'POST') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';
    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    # proxy_pass http://somewhere;
    }
    }

    if ($request_method = 'GET') {
    if ($request_method = 'GET') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';
    add_header 'Access-Control-Allow-Origin' 'http://10.140.10.40';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

    # proxy_pass http://somewhere;
    }
    }
    }

    }
  6. Michiel Kalkman revised this gist Jul 5, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ location / {
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length 0;
    add_header 'Content-Length' 0;

    return 200;
    }
  7. Michiel Kalkman revised this gist Jul 5, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    #
    # Wide-open CORS config for nxginx
    # Wide-open CORS config for nginx
    #

    location / {
  8. Michiel Kalkman created this gist Jul 5, 2011.
    39 changes: 39 additions & 0 deletions cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,39 @@
    #
    # Wide-open CORS config for nxginx
    #

    location / {

    if ($request_method = 'OPTIONS') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length 0;

    return 200;
    }

    if ($request_method = 'POST') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';

    # proxy_pass http://somewhere;
    }

    if ($request_method = 'GET') {

    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'DNT,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control';

    # proxy_pass http://somewhere;
    }
    }