Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added CORS support for rev-proxy APIs #49

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions templates/reverseproxy.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions templates/reverseproxy_ssl.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down