Edit nginx/nginx.conf to enable CORS

This commit is contained in:
Troy McConaghy 2018-10-10 16:17:35 +02:00
parent f1353a3db9
commit c7bc446ec8

View File

@ -82,6 +82,22 @@ http {
# max client request body size: average transaction size. # max client request body size: average transaction size.
client_max_body_size 15k; client_max_body_size 15k;
# GET requests are forwarded to BDB.
if ($request_method = GET) {
proxy_pass http://localhost:9984;
}
# POST requests: Enable CORS then forward to BDB.
if ($request_method = POST) {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
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';
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';
proxy_pass http://localhost:9984;
}
# OPTIONS requests: Enable CORS and return 204.
if ($request_method = 'OPTIONS') { if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
@ -92,8 +108,6 @@ http {
return 204; return 204;
} }
proxy_pass http://localhost:9984;
# Only return this response if request_method is neither POST|GET|OPTIONS # Only return this response if request_method is neither POST|GET|OPTIONS
if ($request_method !~ ^(GET|OPTIONS|POST)$) { if ($request_method !~ ^(GET|OPTIONS|POST)$) {
return 444; return 444;