From 33f72ee8f24176408653f27b32b59117c2eb8f23 Mon Sep 17 00:00:00 2001 From: Alexander Rublev Date: Tue, 13 Nov 2018 09:57:44 +0300 Subject: [PATCH] Allow to generate custom locations in load_balancer mode --- defaults/main.yml | 5 ++++- templates/http/default.conf.j2 | 7 +++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index e558f81..ab13caa 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -168,7 +168,10 @@ nginx_http_template: html_file_name: index.html http_demo_conf: false load_balancer: - proxy_pass: backend + locations: + backend: + location: / + proxy_pass: backend health_check_plus: false upstreams: upstream1: diff --git a/templates/http/default.conf.j2 b/templates/http/default.conf.j2 index 827ad9f..9634427 100644 --- a/templates/http/default.conf.j2 +++ b/templates/http/default.conf.j2 @@ -24,8 +24,9 @@ server { {% endif %} server_name {{ item.value.server_name }}; {% if item.value.load_balancer is defined %} - location / { - proxy_pass http://{{ item.value.load_balancer.proxy_pass }}; +{% for location in item.value.load_balancer.locations %} + location {{ item.value.load_balancer.locations[location].location }} { + proxy_pass http://{{ item.value.load_balancer.locations[location].proxy_pass }}; {% if item.value.load_balancer.health_check_plus %} health_check; {% endif %} @@ -34,6 +35,8 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } + +{% endfor %} {% endif %} {% if item.value.web_server is defined %} location / {