add support to add headers to all vhosts

This commit is contained in:
nd 2020-03-04 23:36:53 +01:00
parent be5b2f4bae
commit b926014bdf
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9
3 changed files with 10 additions and 2 deletions

View file

@ -33,6 +33,9 @@ php: False
# dict of ips to accept "X-Forwarded-~" from # dict of ips to accept "X-Forwarded-~" from
real_ip_from: {"127.0.0.1": {}, "::1": {}} real_ip_from: {"127.0.0.1": {}, "::1": {}}
# array of headers to add on *all* vhosts
add_headers: []
``` ```
**upstreamconfig**: **upstreamconfig**:
@ -72,6 +75,9 @@ custom: []
# array of locations, see below # array of locations, see below
locations: [*locationconfig*, .. ] locations: [*locationconfig*, .. ]
# array of headers to add on this vhost
add_headers: []
``` ```
**locationconfig**: **locationconfig**:

View file

@ -1,5 +1,6 @@
nginx: nginx:
add_headers: []
real_ip_from: real_ip_from:
"127.0.0.1": {} "127.0.0.1": {}
"::1": {} "::1": {}

View file

@ -2,6 +2,7 @@
{% set vhost = item.value %} {% set vhost = item.value %}
{% set vhost_name = item.key %} {% set vhost_name = item.key %}
{% set vhost_listen = vhost.listen|default({}) %} {% set vhost_listen = vhost.listen|default({}) %}
{% set vhost_headers = nginx.add_headers|default({})|combine(vhost.add_headers|default({})) %}
server { server {
{% if vhost.servername|default([])|length > 0 %} {% if vhost.servername|default([])|length > 0 %}
@ -17,8 +18,8 @@ server {
listen [::]:{{ vhost_listen.nossl_port|default(80) }} {% if vhost.default_server|default(False) %}default_server{% endif %}; listen [::]:{{ vhost_listen.nossl_port|default(80) }} {% if vhost.default_server|default(False) %}default_server{% endif %};
{% endif %} {% endif %}
{% for header in vhost.add_headers|default([]) %} {% for header in vhost_headers if header %}
add_header {{ header }} "{{ vhost.add_headers[header] }}"; add_header {{ header }} "{{ vhost_headers[header] }}";
{% endfor %} {% endfor %}
{% for c in vhost.custom|default([]) %} {% for c in vhost.custom|default([]) %}