added CORS rules

This commit is contained in:
joglomedia
2019-09-03 17:20:20 +07:00
parent ba73ff8cc2
commit 334ae073bb

View File

@@ -0,0 +1,38 @@
# Enable CORS
# Allow cross-origin requests.
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS
# https://enable-cors.org/
# https://www.w3.org/TR/cors/
# (!) Do not use this without understanding the consequences.
# This will permit access from any other website.
# Instead of using this file, consider using a specific rule such as
# allowing access based on (sub)domain:
#
# add_header Access-Control-Allow-Origin "subdomain.example.com";
# Simple requests
if ($request_method ~* "(GET|POST)") {
# Wildcard allow all origin
#add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Origin $cors;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD";
add_header Access-Control-Expose-Headers "Content-Length, Content-Range";
add_header Access-Control-Allow-Headers "Authorization, Origin, DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Accept, Range";
}
# Pre-flighted requests
if ($request_method = OPTIONS) {
# Wildcard allow all origin
#add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Origin $cors;
add_header Access-Control-Allow-Methods "GET, POST, OPTIONS, HEAD";
add_header Access-Control-Allow-Headers "Authorization, Origin, DNT, User-Agent, X-Requested-With, If-Modified-Since, Cache-Control, Content-Type, Accept, Range";
add_header Access-Control-Max-Age 1728000;
add_header Content-Type "text/plain; charset=utf-8";
add_header Content-Length 0;
return 200;
}