diff --git a/defaults/main.yml b/defaults/main.yml index dc8e63a..aa3987e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -14,6 +14,7 @@ nginx_revproxy_sites: # List of sites to hsts_max_age: 63072000 # Set HSTS header with max-age defined letsencrypt: false # Set to True if you want use letsencrypt letsencrypt_email: "" # Set email for letencrypt cert + allow_cors: false # Set to True if you want to allow Cross-Origin requests nginx_revproxy_certbot_auto: false diff --git a/templates/reverseproxy.conf.j2 b/templates/reverseproxy.conf.j2 index 3439de9..aaf50f0 100644 --- a/templates/reverseproxy.conf.j2 +++ b/templates/reverseproxy.conf.j2 @@ -27,12 +27,18 @@ server { listen [::]:{{ item.value.listen | default(80) }}; server_name {{ item.value.domains | join(' ') }}; +{% if item.value.allow_cors is defined and item.value.allow_cors %} + add_header 'Access-Control-Allow-Origin' $http_origin; + add_header 'Access-Control-Max-Age' 600; +{% endif %} + location / { gzip off; client_max_body_size {{ item.value.client_max_body_size | default('50M') }}; proxy_read_timeout {{ item.value.proxy_read_timeout | default('300') }}; proxy_set_header Upgrade $http_upgrade; {% if item.value.conn_upgrade is not defined or item.value.conn_upgrade %} + proxy_http_version 1.1; proxy_set_header Connection "upgrade"; {% endif %} proxy_set_header Host $http_host; diff --git a/templates/reverseproxy_ssl.conf.j2 b/templates/reverseproxy_ssl.conf.j2 index fb8f073..f45718f 100644 --- a/templates/reverseproxy_ssl.conf.j2 +++ b/templates/reverseproxy_ssl.conf.j2 @@ -66,6 +66,11 @@ server { add_header Strict-Transport-Security "max-age={{ item.value.hsts_max_age }}; includeSubDomains; preload" always; {% endif %} +{% if item.value.allow_cors is defined and item.value.allow_cors %} + add_header 'Access-Control-Allow-Origin' $http_origin; + add_header 'Access-Control-Max-Age' 600; +{% endif %} + access_log /var/log/nginx/{{ item.key }}_access.log; error_log /var/log/nginx/{{ item.key }}_error.log error; @@ -93,6 +98,7 @@ server { proxy_read_timeout {{ item.value.proxy_read_timeout | default('300') }}; proxy_set_header Upgrade $http_upgrade; {% if item.value.conn_upgrade is not defined or item.value.conn_upgrade %} + proxy_http_version 1.1; proxy_set_header Connection "upgrade"; {% endif %} proxy_set_header Host $http_host;