library/roles/nginx: Optionally limit CORS access.

This commit is contained in:
Andrea Dell'Amico 2016-11-28 16:45:01 +01:00
parent 00b6c78bb6
commit cffd1ce098
2 changed files with 11 additions and 6 deletions

View File

@ -56,6 +56,7 @@ nginx_proxy_send_timeout: 120s
nginx_client_max_body_size: 32000M
nginx_client_body_timeout: 240s
nginx_cors_limit_origin: False
nginx_cors_acl_origin: 'http?://(localhost)'
# Find a set of acceptable defaults for the cache setup

View File

@ -1,13 +1,17 @@
# set $cors '';
# if ($http_origin ~* '{{ nginx_cors_acl_origin }}') {
# set $cors 'true';
# }
# if ($cors = 'true') {
{% if nginx_cors_limit_origin %}
set $cors '';
if ($http_origin ~* '{{ nginx_cors_acl_origin }}') {
set $cors 'true';
}
if ($cors = 'true') {
{% endif %}
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, 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 nginx_cors_limit_origin %}
}
{% endif %}
if ($request_method = 'OPTIONS') {
return 204;
}