Skip to content

Instantly share code, notes, and snippets.

@DanyC97
Forked from Stanback/nginx.conf
Created March 28, 2024 16:57

Revisions

  1. Brian Stanback revised this gist Nov 8, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -15,7 +15,7 @@
    #

    set $cors '';
    if ($http_origin ~* 'https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)') {
    if ($http_origin ~ '^https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)') {
    set $cors 'true';
    }

  2. Brian Stanback revised this gist Nov 8, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    # include cors_support;
    #
    # As of Nginx 1.7.5, add_header supports an "always" parameter which
    # allows CORS to work if the backend returns 4xx or 5xx status cocde.
    # allows CORS to work if the backend returns 4xx or 5xx status code.
    #
    # For more information on CORS, please see: http://enable-cors.org/
    # Forked from this Gist: https://gist.github.com/michiel/1064640
  3. Brian Stanback revised this gist Nov 8, 2016. 1 changed file with 13 additions and 7 deletions.
    20 changes: 13 additions & 7 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -3,12 +3,12 @@
    #
    # One way to use this is by placing it into a file called "cors_support"
    # under your Nginx configuration directory and placing the following
    # statement inside your location block(s):
    # statement inside your **location** block(s):
    #
    # include cors_support;
    #
    # A limitation to this method is that Nginx doesn't currently send headers
    # specified by add_header when the backend returns a 4xx or 5xx status code.
    # As of Nginx 1.7.5, add_header supports an "always" parameter which
    # allows CORS to work if the backend returns 4xx or 5xx status cocde.
    #
    # For more information on CORS, please see: http://enable-cors.org/
    # Forked from this Gist: https://gist.github.com/michiel/1064640
    @@ -20,12 +20,18 @@ if ($http_origin ~* 'https?://(localhost|www\.yourdomain\.com|www\.yourotherdoma
    }

    if ($cors = 'true') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With';
    add_header 'Access-Control-Allow-Origin' "$http_origin" always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With' always;
    # required to be able to read Authorization header in frontend
    #add_header 'Access-Control-Expose-Headers' 'Authorization' always;
    }

    if ($request_method = 'OPTIONS') {
    # Tell client that this pre-flight info is valid for 20 days
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;
    return 204;
    }
  4. Brian Stanback revised this gist Nov 8, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@ if ($cors = 'true') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Requested-With';
    }

    if ($request_method = 'OPTIONS') {
  5. @Stanback Stanback renamed this gist Jan 7, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  6. @Stanback Stanback renamed this gist Jan 7, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  7. @Stanback Stanback revised this gist Dec 10, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -27,7 +27,5 @@ if ($cors = 'true') {
    }

    if ($request_method = 'OPTIONS') {
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Length' 0;
    return 204;
    }
  8. @Stanback Stanback revised this gist Dec 10, 2013. 1 changed file with 6 additions and 17 deletions.
    23 changes: 6 additions & 17 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -14,31 +14,20 @@
    # Forked from this Gist: https://gist.github.com/michiel/1064640
    #

    set $cors "false";
    set $cors '';
    if ($http_origin ~* 'https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)') {
    set $cors "true";
    }
    if ($request_method = 'OPTIONS') {
    set $cors "${cors}_preflight";
    }
    if ($request_method ~ ^(GET|POST|PUT|DELETE)$) {
    set $cors "${cors}_request";
    set $cors 'true';
    }

    if ($cors = 'true_preflight') {
    if ($cors = 'true') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
    }

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

    if ($cors = 'true_request') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
    add_header 'Access-Control-Allow-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
    }
  9. @Stanback Stanback revised this gist Oct 29, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ if ($http_origin ~* 'https?://(localhost|www\.yourdomain\.com|www\.yourotherdoma
    if ($request_method = 'OPTIONS') {
    set $cors "${cors}_preflight";
    }
    if ($request_method ~ GET|POST|PUT|DELETE) {
    if ($request_method ~ ^(GET|POST|PUT|DELETE)$) {
    set $cors "${cors}_request";
    }

  10. @Stanback Stanback revised this gist Oct 29, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,9 @@
    #
    # include cors_support;
    #
    # A limitation to this method is that Nginx doesn't currently send headers
    # specified by add_header when the backend returns a 4xx or 5xx status code.
    #
    # For more information on CORS, please see: http://enable-cors.org/
    # Forked from this Gist: https://gist.github.com/michiel/1064640
    #
  11. @Stanback Stanback revised this gist Oct 24, 2013. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ if ($cors = 'true_preflight') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, 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-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;
    @@ -37,5 +37,5 @@ if ($cors = 'true_request') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, 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-Headers' 'Accept,Authorization,Cache-Control,Content-Type,DNT,If-Modified-Since,Keep-Alive,Origin,User-Agent,X-Mx-ReqToken,X-Requested-With';
    }
  12. @Stanback Stanback revised this gist Oct 24, 2013. 2 changed files with 41 additions and 52 deletions.
    52 changes: 0 additions & 52 deletions cors-nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,52 +0,0 @@
    #
    # Wide-open CORS config for nginx
    #
    location / {

    if ($request_method = 'OPTIONS') {

    add_header 'Access-Control-Allow-Origin' '*';

    #
    # Om nom nom cookies
    #

    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
    #

    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
    #

    add_header 'Access-Control-Max-Age' 1728000;
    add_header 'Content-Type' 'text/plain charset=UTF-8';
    add_header 'Content-Length' 0;

    return 204;
    }

    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,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';

    }

    }
    41 changes: 41 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #
    # CORS header support
    #
    # One way to use this is by placing it into a file called "cors_support"
    # under your Nginx configuration directory and placing the following
    # statement inside your location block(s):
    #
    # include cors_support;
    #
    # For more information on CORS, please see: http://enable-cors.org/
    # Forked from this Gist: https://gist.github.com/michiel/1064640
    #

    set $cors "false";
    if ($http_origin ~* 'https?://(localhost|www\.yourdomain\.com|www\.yourotherdomain\.com)') {
    set $cors "true";
    }
    if ($request_method = 'OPTIONS') {
    set $cors "${cors}_preflight";
    }
    if ($request_method ~ GET|POST|PUT|DELETE) {
    set $cors "${cors}_request";
    }

    if ($cors = 'true_preflight') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, 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 204;
    }

    if ($cors = 'true_request') {
    add_header 'Access-Control-Allow-Origin' "$http_origin";
    add_header 'Access-Control-Allow-Credentials' 'true';
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, 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';
    }
  13. @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';
  14. 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
  15. 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';

    }

    }
  16. 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;
    }
    }
    }

    }
  17. 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;
    }
  18. 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 / {
  19. 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;
    }
    }