diff --git a/roles/vhost/defaults/main.yaml b/roles/vhost/defaults/main.yaml index dc97331..ac5fb79 100644 --- a/roles/vhost/defaults/main.yaml +++ b/roles/vhost/defaults/main.yaml @@ -14,6 +14,7 @@ vhost_basicauth_users: {} vhost_proxy_target_netproto: tcp vhost_proxy_target_protocol: http vhost_proxy_target_host: localhost +vhost_proxy_headers: {} vhost_proxy_delete_headers: [] vhost_proxy_pass_host_header: true diff --git a/roles/vhost/meta/argument_specs.yaml b/roles/vhost/meta/argument_specs.yaml index a690ad0..2471c03 100644 --- a/roles/vhost/meta/argument_specs.yaml +++ b/roles/vhost/meta/argument_specs.yaml @@ -103,6 +103,11 @@ argument_specs: - Only applicable if vhost_type is reverse_proxy and vhost_proxy_target_netproto is unix. type: str required: false + vhost_proxy_headers: + description: Dict of request headers and their values to set for proxied requests + type: dict + required: false + default: {} vhost_proxy_delete_headers: description: List of headers to delete from proxied requests type: list @@ -229,6 +234,11 @@ argument_specs: type: str required: false default: "{{ vhost_proxy_target_socket if vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'unix' else '' }}" + proxy_headers: + description: Dict of request headers and their values to set for proxied requests + type: dict + required: false + default: "{{ vhost_proxy_headers }}" proxy_delete_headers: description: List of request headers to delete from proxied requests type: list diff --git a/roles/vhost/templates/Caddyfile_block.j2 b/roles/vhost/templates/Caddyfile_block.j2 index 377092a..a9e5b47 100644 --- a/roles/vhost/templates/Caddyfile_block.j2 +++ b/roles/vhost/templates/Caddyfile_block.j2 @@ -33,7 +33,10 @@ {% for header in location.proxy_delete_headers %} header_up -{{ header }} {% endfor %} - {% if not location.proxy_pass_host_header %} + {% for header in location.proxy_headers | dict2items %} + header_up {{ header.key }} `{{ header.value }}` + {% endfor %} + {% if (not location.proxy_pass_host_header) and ('host' not in location.proxy_headers | map('lower')) %} header_up Host {upstream_hostport} {% endif %} } diff --git a/roles/vhost/vars/main.yaml b/roles/vhost/vars/main.yaml index 494af0d..dd04db7 100644 --- a/roles/vhost/vars/main.yaml +++ b/roles/vhost/vars/main.yaml @@ -14,6 +14,7 @@ _vhost_location_defaults: vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'tcp' else '' }}" proxy_target_socket: "{{ vhost_proxy_target_socket if vhost_type == 'reverse_proxy' and vhost_proxy_target_netproto == 'unix' else '' }}" + proxy_headers: "{{ vhost_proxy_headers }}" proxy_delete_headers: "{{ vhost_proxy_delete_headers }}" proxy_pass_host_header: "{{ vhost_proxy_pass_host_header }}"