From bd09ecd85eb55cef7079ee97fd1fb94580f1026c Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Thu, 3 Jan 2019 14:14:25 -0800 Subject: [PATCH] Add support for enabling an http to https redirects (#82) * Add support for enabling an http to https redirects * Remove extra curly brace * Update default.conf.j2 Remove another extra curly brace * Add redirect variable to defaults and readme --- README.md | 1 + defaults/main.yml | 1 + templates/http/default.conf.j2 | 3 +++ 3 files changed, 5 insertions(+) diff --git a/README.md b/README.md index a193245..bc60429 100644 --- a/README.md +++ b/README.md @@ -328,6 +328,7 @@ nginx_http_template: port: 8081 server_name: localhost error_page: /usr/share/nginx/html + redirect: false autoindex: false ssl: cert: ssl/default.crt diff --git a/defaults/main.yml b/defaults/main.yml index cd4b287..a7db8f8 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -161,6 +161,7 @@ nginx_http_template: port: 8081 server_name: localhost error_page: /usr/share/nginx/html + redirect: false autoindex: false ssl: cert: ssl/default.crt diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index c107cab..b40a328 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -28,6 +28,9 @@ server { {% if item.value.autoindex is defined and item.value.autoindex %} autoindex on; {% endif %} +{% if item.value.redirect is defined and item.value.redirect %} + return 301 https://{{ item.value.server_name }}$request_uri; +{% endif%} {% if item.value.load_balancer is defined %} {% for location in item.value.load_balancer.locations %} location {{ item.value.load_balancer.locations[location].location }} {