1- proxy_hide_header 'Access-Control-Allow-Origin';
1+ proxy_hide_header 'Access-Control-Allow-Origin';
22
3- if ( $access_control_allow_origin ~ "^$" ) {
4- set $access_control_allow_origin '*';
5- }
3+ # assumes that the server default is configured or overriden by a specific location block as needed
4+ # if explicitly set to empty, align it with the standard value allowing any origin
5+ if ( $access_control_allow_origin ~ "^$" ) {
6+ set $access_control_allow_origin '*';
7+ }
68
7- set $vary_origin ""; # nginx will omit this header value if set to the empty string
8- if ( $access_control_allow_origin != '*' ) {
9- set $vary_origin Origin;
10- }
9+ set $vary_origin ""; # nginx will omit this header value if set to the empty string
10+ if ( $access_control_allow_origin != '*' ) {
11+ set $vary_origin Origin;
12+ }
1113
12- if ($request_method = 'OPTIONS') {
13- add_header 'Access-Control-Allow-Origin ' $access_control_allow_origin ;
14- add_header Vary $vary_origin ;
15- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
16- #
17- # Custom headers and headers various browsers *should* be OK with but aren't
18- #
19- add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
20- #
21- # Tell client that this pre-flight info is valid for 20 days
22- #
23- add_header 'Access-Control-Max-Age' 1728000;
24- add_header 'Content-Type' 'text/plain; charset=utf-8';
25- add_header 'Content-Length' 0;
26- return 204;
27- }
28- if ($request_method = 'POST') {
29- add_header 'Access-Control-Allow-Origin ' $access_control_allow_origin ;
30- add_header Vary $vary_origin ;
31- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
32- add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
33- add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
34- }
35- if ($request_method = 'GET') {
36- add_header 'Access-Control-Allow-Origin ' $access_control_allow_origin ;
37- add_header Vary $vary_origin ;
38- add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
39- add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
40- add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
41- }
14+ if ($request_method = 'OPTIONS') {
15+ add_header 'Vary ' $vary_origin ;
16+ add_header 'Access-Control-Allow-Origin' $access_control_allow_origin ;
17+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
18+ #
19+ # Custom headers and headers various browsers *should* be OK with but aren't
20+ #
21+ add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
22+ #
23+ # Tell client that this pre-flight info is valid for 20 days
24+ #
25+ add_header 'Access-Control-Max-Age' 1728000;
26+ add_header 'Content-Type' 'text/plain; charset=utf-8';
27+ add_header 'Content-Length' 0;
28+ return 204;
29+ }
30+ if ($request_method = 'POST') {
31+ add_header 'Vary ' $vary_origin ;
32+ add_header 'Access-Control-Allow-Origin' $access_control_allow_origin ;
33+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
34+ add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
35+ add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
36+ }
37+ if ($request_method = 'GET') {
38+ add_header 'Vary ' $vary_origin ;
39+ add_header 'Access-Control-Allow-Origin' $access_control_allow_origin ;
40+ add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
41+ add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
42+ add_header 'Access-Control-Expose-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
43+ }
0 commit comments