From a8b7fff7fcdc9d15a5f835ddb028e62a42035b59 Mon Sep 17 00:00:00 2001 From: Philip Henning Date: Wed, 17 Jul 2019 14:10:09 +0200 Subject: [PATCH] Return (#148) * Add possibity to just have a location with a return in it. --- README.md | 8 ++++++++ defaults/main.yml | 5 +++++ templates/http/default.conf.j2 | 7 +++++++ tests/playbooks/nginx-http-template.yml | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/README.md b/README.md index 38786ca..8348503 100644 --- a/README.md +++ b/README.md @@ -550,6 +550,14 @@ nginx_http_template: port: 8081 weight: 1 health_check: max_fails=1 fail_timeout=10s + returns: + return301: + location: / + code: 301 + value: http://$host$request_uri + return404: + location: /setup + code: 404 # Enable NGINX status data. # Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus. diff --git a/defaults/main.yml b/defaults/main.yml index 12aaa8e..b13792c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -362,6 +362,11 @@ nginx_http_template: port: 8081 weight: 1 health_check: max_fails=1 fail_timeout=10s + returns: + return301: + location: / + code: 301 + value: http://$host$request_uri # Enable NGINX status data. # Will enable 'stub_status' in NGINX Open Source and 'status' in NGINX Plus. diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index f016732..0b009e4 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -352,6 +352,13 @@ server { sub_filter 'proxied_for_ip' '$http_x_forwarded_for'; {% endif %} {% endif %} +{% if item.value.returns is defined %} +{% for return in item.value.returns %} + location {{ item.value.returns[return].location }} { + return {{ item.value.returns[return].code }}{% if item.value.returns[return].value is defined %} {{ item.value.returns[return].value }}{% endif %}; + } +{% endfor %} +{% endif %} {% if item.value.error_page is defined %} # redirect server error pages to the static page /50x.html # diff --git a/tests/playbooks/nginx-http-template.yml b/tests/playbooks/nginx-http-template.yml index f11b775..26ddac0 100644 --- a/tests/playbooks/nginx-http-template.yml +++ b/tests/playbooks/nginx-http-template.yml @@ -147,6 +147,11 @@ port: 8082 weight: 1 health_check: max_fails=3 fail_timeout=5s + returns: + return301: + location: ^~ /old-path + code: 301 + value: http://$host/new-path frontend: template_file: http/default.conf.j2 conf_file_name: frontend_default.conf