From 7785babce1953c7602245bf8bcc66bd7cddbf1e4 Mon Sep 17 00:00:00 2001 From: scodeman <30977678+scodeman@users.noreply.github.com> Date: Tue, 5 Nov 2019 06:41:25 +0800 Subject: [PATCH] Add support for multiple rewrite directives as per nginx conf (#176) --- README.md | 3 ++- defaults/main.yml | 3 ++- templates/http/default.conf.j2 | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 4da9786..5ab3e5d 100644 --- a/README.md +++ b/README.md @@ -490,7 +490,8 @@ nginx_http_template: #always: false proxy_connect_timeout: null proxy_pass: http://backend - #rewrite: /foo(.*) /$1 break + #rewrites: + # - /foo(.*) /$1 break #proxy_pass_request_body: off #allows: # - 192.168.1.0/24 diff --git a/defaults/main.yml b/defaults/main.yml index 167cd95..3570d68 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -304,7 +304,8 @@ nginx_http_template: #always: false proxy_connect_timeout: null proxy_pass: http://backend - #rewrite: /foo(.*) /$1 break + #rewrites: + # - /foo(.*) /$1 break #proxy_pass_request_body: off #allows: # - 192.168.1.0/24 diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index 4e3855c..80681f1 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -196,8 +196,10 @@ server { proxy_connect_timeout {{ item.value.reverse_proxy.locations[location].proxy_connect_timeout }}; {% endif %} proxy_pass {{ item.value.reverse_proxy.locations[location].proxy_pass }}; -{% if item.value.reverse_proxy.locations[location].rewrite is defined %} - rewrite {{ item.value.reverse_proxy.locations[location].rewrite }}; +{% if item.value.reverse_proxy.locations[location].rewrites is defined %} +{% for rewrite in item.value.reverse_proxy.locations[location].rewrites %} + rewrite {{ rewrite }}; +{% endfor %} {% endif %} {% if item.value.reverse_proxy.locations[location].proxy_read_timeout is defined and item.value.reverse_proxy.locations[location].proxy_read_timeout %} proxy_read_timeout {{ item.value.reverse_proxy.locations[location].proxy_read_timeout }};