Skip to content

Commit a6b7e04

Browse files
author
Michael Grauer
committed
Enable cors for * origins on nginx
1 parent e539fc1 commit a6b7e04

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

ansible/roles/nginx/templates/nginx.conf.j2

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ server {
2424
proxy_set_header X-Forwarded-Server $host;
2525
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
2626
proxy_pass http://127.0.0.1:8080/geoserver/;
27+
if ($request_method = 'OPTIONS') {
28+
add_header 'Access-Control-Allow-Origin' '*';
29+
#
30+
add_header 'Access-Control-Allow-Credentials' 'true';
31+
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
32+
#
33+
# Custom headers and headers various browsers *should* be OK with but aren't
34+
#
35+
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
36+
#
37+
# Tell client that this pre-flight info is valid for 30 min.
38+
#
39+
add_header 'Access-Control-Max-Age' 1800;
40+
add_header 'Content-Type' 'text/plain charset=UTF-8';
41+
add_header 'Content-Length' 0;
42+
return 204;
43+
}
44+
if ($request_method = 'GET') {
45+
add_header 'Access-Control-Allow-Origin' '*';
46+
add_header 'Access-Control-Allow-Credentials' 'true';
47+
add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
48+
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
49+
}
2750
}
2851

2952
}

0 commit comments

Comments
 (0)