diff --git a/defaults/main.yml b/defaults/main.yml index bbd7383e760f6b0e7bbf692b01250c3afe4bde63..a63a4faca0f8e6b52b9112d7765e2a742e342f6e 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -8,6 +8,9 @@ proxy_timeout_server: '45s' proxy_redirect_aliase: false proxy_maxconn: 100 proxy_varnish_maxconn: 1000 +proxy_redirect_maps: + domain: {} + path: {} proxy_blacklist: ip: - '146.185.176.158' diff --git a/tasks/configure.yml b/tasks/configure.yml index 55c4a0caf9591278f93c6c18c4ca0fe806391e0a..8e783dffb99925f3682a5e5837659d6c638dae3b 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -105,6 +105,18 @@ when: haproxy_private is defined and haproxy_private.domain is defined notify: "Check HAProxy Config" +- name: "Update redirect map files" + template: + src='redirect.map.jinja2' + dest='/etc/haproxy/redirect.{{ item }}.map' + owner='root' + group='root' + mode='644' + with_items: + - 'domain' + - 'path' + notify: "Check HAProxy Config" + - name: "Create config file" template: src='haproxy_cfg.jinja2' diff --git a/templates/haproxy_cfg.jinja2 b/templates/haproxy_cfg.jinja2 index 33cd2fb5d18d1f61b5046efbd3ec4ee19a4239f4..3dfc81781157a8330d51a007a2717c78569dd34d 100644 --- a/templates/haproxy_cfg.jinja2 +++ b/templates/haproxy_cfg.jinja2 @@ -60,6 +60,8 @@ userlist notprivate frontend http_in bind *:80 http-request del-header Proxy + http-request redirect code 301 location %[hdr(host),map(/etc/haproxy/redirect.domain.map)] if { hdr(host),map(/etc/haproxy/redirect.domain.map) -m found } + http-request redirect code 301 location %[capture.req.uri,map(/etc/haproxy/redirect.path.map)] if { capture.req.uri,map(/etc/haproxy/redirect.path.map) -m found } {% if haproxy_private is defined %} {% if haproxy_private.domain is defined %} acl privatedomain hdr(host) -i -n -f /etc/haproxy/privatelist.domain @@ -187,6 +189,8 @@ frontend http_in frontend https_in_{{ cert.ip }} bind {{ cert.ip }}:443 ssl crt /etc/haproxy/certs/{{ cert.file }} no-sslv3 http-request del-header Proxy + http-request redirect code 301 location %[hdr(host),map(/etc/haproxy/redirect.domain.map)] if { hdr(host),map(/etc/haproxy/redirect.domain.map) -m found } + http-request redirect code 301 location %[capture.req.uri,map(/etc/haproxy/redirect.path.map)] if { capture.req.uri,map(/etc/haproxy/redirect.path.map) -m found } {% if haproxy_private is defined %} {% if haproxy_private.domain is defined %} acl privatedomain hdr(host) -i -n -f /etc/haproxy/privatelist.domain diff --git a/templates/redirect.map.jinja2 b/templates/redirect.map.jinja2 new file mode 100644 index 0000000000000000000000000000000000000000..e3765f916587f250d7b83ef184f3fe4c62565646 --- /dev/null +++ b/templates/redirect.map.jinja2 @@ -0,0 +1,3 @@ +{% for key in proxy_redirect_maps[item] %} +{{ key }} {{ proxy_redirect_maps[item][key] }} +{% endfor %}