From 469d663bc25f86273fcb7c618ddbce529bbf302b Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Mon, 18 Feb 2019 21:23:57 +0700 Subject: [PATCH] Add proxy_redirect parameter for location blocks (#102) * Add proxy_redirect parameter for http and location blocks (#1) * Use ternary() filter to handle proxy_redirect parameter --- README.md | 1 + templates/http/default.conf.j2 | 4 +++- tests/playbooks/nginx-http-template.yml | 2 ++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 704a88a..832a9e2 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,7 @@ nginx_http_template: proxy_ignore_headers: - Vary - Cache-Control + proxy_redirect: false websocket: false auth_basic: null auth_basic_file: null diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index 13d728d..480efdd 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -75,7 +75,9 @@ server { auth_basic_user_file {{ item.value.reverse_proxy.locations[location].auth_basic_file }}; {% endif %} proxy_pass {{ item.value.reverse_proxy.locations[location].proxy_pass }}; - +{% if item.value.reverse_proxy.locations[location].proxy_redirect is defined %} + proxy_redirect {{ item.value.reverse_proxy.locations[location].proxy_redirect | ternary(item.value.reverse_proxy.locations[location].proxy_redirect, "off") }}; +{% endif %} {% if item.value.reverse_proxy.locations[location].proxy_cache is defined %} proxy_cache {{ item.value.reverse_proxy.locations[location].proxy_cache }}; {% endif %} diff --git a/tests/playbooks/nginx-http-template.yml b/tests/playbooks/nginx-http-template.yml index 6dc169e..088b1ab 100644 --- a/tests/playbooks/nginx-http-template.yml +++ b/tests/playbooks/nginx-http-template.yml @@ -59,6 +59,7 @@ proxy_ignore_headers: - Vary - Cache-Control + proxy_redirect: false backend: location: /backend proxy_pass: http://backend_servers/ @@ -72,6 +73,7 @@ - http_500 - http_502 - http_503 + proxy_redirect: default upstreams: frontend_upstream: name: frontend_servers