diff --git a/tasks/configure.yml b/tasks/configure.yml index 0e9b8d1567550ea5e2386a16f545b875c40c94af..715111081f051b03254e16d1e874d1c1720544d9 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -29,6 +29,16 @@ with_items: '{{ groups.webserver }}' notify: 'Proxy | Restart HAProxy' +- name: "Proxy | Create host path lists" + file: + dest='/etc/haproxy/{{item}}.path.list' + owner='root' + group='root' + mode='644' + state='touch' + with_items: '{{ groups.webserver }}' + changed_when: false + - name: "Proxy | Create use bigpipe host lists" template: src='use_bigpipe_list' diff --git a/templates/haproxy_cfg b/templates/haproxy_cfg index b3915ed5b5ef66771bbfccca5f9c9c52e12c2189..f0a4a62211275c0c2db134d0569d24b1971c9639 100644 --- a/templates/haproxy_cfg +++ b/templates/haproxy_cfg @@ -62,6 +62,7 @@ frontend http_in {% for rule in proxy_blacklist.other|default([]) %} http-request deny if { {{ rule }} } {% endfor %} + http-request set-header x-routing-host undefined {% for host in groups['all'] %} {% for redirect in hostvars[host].proxy_redirect|default([]) %} {% for from in redirect.from %} @@ -104,6 +105,21 @@ frontend http_in {% endfor %} {% endif %} {% endfor %} +{% for host in groups['webserver'] %} +{% if hostvars[host].routing is defined %} + http-request set-header x-routing-host {{ host }} if { hdr(x-routing-host) undefined } { hdr(host) -i -n {{ hostvars[host].routing.domain }} } { path -i -n -f /etc/haproxy/{{ host }}.path.list } +{% endif %} +{% endfor %} +{% for host in groups['webserver'] %} +{% if hostvars[host].routing is defined %} +{% for path in hostvars[host].routing.paths|default([]) %} + http-request set-header x-routing-host {{ host }} if { hdr(x-routing-host) undefined } { hdr(host) -i -n {{ hostvars[host].routing.domain }} } { path_beg {{ path }} } +{% endfor %} +{% endif %} +{% endfor %} +{% if routing is defined and routing.default is defined %} + http-request set-header x-routing-host {{ routing.default }} if { hdr(x-routing-host) undefined } { hdr(host) -i -n {{ routing.domain }} } +{% endif %} {% if kibana_users is defined %} acl kibana_present hdr(host) -i -n '{{ kibana_domain|default(inventory_hostname) }}' use_backend backend_redirect_ssl if kibana_present @@ -123,6 +139,10 @@ frontend http_in acl static_content path_end .jpg .jpeg .gif .png .ico .swf .css .js .htm .html use_backend backend_varnish if static_content !domain_ignores_varnish {% endif %} +{% for host in groups['webserver'] %} + use_backend backend_{{ host }}_bigpipe if domain_uses_bigpipe { hdr(x-routing-host) {{ host }} } + use_backend backend_{{ host }} if { hdr(x-routing-host) {{ host }} } +{% endfor %} {% for host in groups['webserver'] %} acl domain_in_{{host}} hdr(host) -i -n -f /etc/haproxy/{{host}}.list use_backend backend_{{host}}_bigpipe if domain_uses_bigpipe domain_in_{{host}} @@ -150,6 +170,7 @@ frontend https_in_{{ cert.ip }} {% for rule in proxy_blacklist.other|default([]) %} http-request deny if { {{ rule }} } {% endfor %} + http-request set-header x-routing-host undefined {% for host in groups['all'] %} {% for redirect in hostvars[host].proxy_redirect|default([]) %} {% for from in redirect.from %} @@ -192,6 +213,21 @@ frontend https_in_{{ cert.ip }} {% endfor %} {% endif %} {% endfor %} +{% for host in groups['webserver'] %} +{% if hostvars[host].routing is defined %} + http-request set-header x-routing-host {{ host }} if { hdr(x-routing-host) undefined } { hdr(host) -i -n {{ hostvars[host].routing.domain }} } { path -i -n -f /etc/haproxy/{{ host }}.path.list } +{% endif %} +{% endfor %} +{% for host in groups['webserver'] %} +{% if hostvars[host].routing is defined %} +{% for path in hostvars[host].routing.paths|default([]) %} + http-request set-header x-routing-host {{ host }} if { hdr(x-routing-host) undefined } { hdr(host) -i -n {{ hostvars[host].routing.domain }} } { path_beg {{ path }} } +{% endfor %} +{% endif %} +{% endfor %} +{% if routing is defined and routing.default is defined %} + http-request set-header x-routing-host {{ routing.default }} if { hdr(x-routing-host) undefined } { hdr(host) -i -n {{ routing.domain }} } +{% endif %} {% if kibana_users is defined %} acl kibana_present hdr(host) -i -n '{{ kibana_domain|default(inventory_hostname) }}' use_backend backend_kibana if kibana_present @@ -211,6 +247,10 @@ frontend https_in_{{ cert.ip }} acl static_content path_end .jpg .jpeg .gif .png .ico .swf .css .js .htm .html use_backend backend_varnish if static_content !domain_ignores_varnish {% endif %} +{% for host in groups['webserver'] %} + use_backend backend_{{ host }}_https_bigpipe if domain_uses_bigpipe { hdr(x-routing-host) {{ host }} } + use_backend backend_{{ host }}_https if { hdr(x-routing-host) {{ host }} } +{% endfor %} {% for host in groups['webserver'] %} acl ssl_domain_in_{{host}} hdr(host) -i -n -f /etc/haproxy/{{host}}.ssl.list use_backend backend_{{host}}_https_bigpipe if domain_uses_bigpipe ssl_domain_in_{{host}} diff --git a/templates/host_list b/templates/host_list index 2ebc16e8804edb19a830a81509dfc51ba1383cf6..8eeb596d3dcf4d36962763cfafb2539799a0af8a 100644 --- a/templates/host_list +++ b/templates/host_list @@ -3,11 +3,13 @@ {% endfor %} {% for drupal in hostvars[item].drupal_settings|default([]) %} {% for domain in drupal.domains|default([]) %} +{% if domain.route_by_domain|default(true) %} {% if domain.protocol|default('https') == 'http' %} {{domain.domain}} {% for alias in domain.aliases|default([]) %} {{alias}} {% endfor %} {% endif %} +{% endif %} {% endfor %} {% endfor %} diff --git a/templates/host_ssl_list b/templates/host_ssl_list index f51782b2cb32748174a7588680368e05605160f3..3c4326a5211f098d3e59e908f4a7f67d9060b0d8 100644 --- a/templates/host_ssl_list +++ b/templates/host_ssl_list @@ -3,11 +3,13 @@ {% endfor %} {% for drupal in hostvars[item].drupal_settings|default([]) %} {% for domain in drupal.domains|default([]) %} +{% if domain.route_by_domain|default(true) %} {% if domain.protocol|default('https') == 'https' %} {{domain.domain}} {% for alias in domain.aliases|default([]) %} {{alias}} {% endfor %} {% endif %} +{% endif %} {% endfor %} {% endfor %}