From b533542b577665d9ac4c2b4442e03db5efd6f88f Mon Sep 17 00:00:00 2001 From: Timo Makinen Date: Thu, 6 Jun 2019 01:56:00 +0300 Subject: [PATCH] add support for defining multiple upstream servers for proxy sites --- roles/nginx/site/templates/site.conf.j2 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/roles/nginx/site/templates/site.conf.j2 b/roles/nginx/site/templates/site.conf.j2 index 7c1c24a..6e28525 100644 --- a/roles/nginx/site/templates/site.conf.j2 +++ b/roles/nginx/site/templates/site.conf.j2 @@ -1,4 +1,10 @@ - +{% if proxy is defined and proxy is not string %} +upstream upstream_{{ site }} { +{% for item in proxy %} + server {{ item }}:443; +{% endfor %} +} +{% endif %} server { listen 443 ssl; listen [::]:443 ssl; @@ -11,7 +17,11 @@ server { return 301 {{ redirect }}; {% elif proxy is defined %} location / { +{% if proxy is not string %} + proxy_pass https://upstream_{{ site }}; +{% else %} proxy_pass {{ proxy }}; +{% endif %} proxy_ssl_certificate {{ tls_certs }}/{{ inventory_hostname }}.crt; proxy_ssl_certificate_key {{ tls_private }}/{{ inventory_hostname }}.key; }