From 1f4510181e79bf58fbb06649ab5c9c062e8e1dbf Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Sun, 9 May 2021 16:54:56 +0200 Subject: [PATCH] upstream backends in the virtualhost template. --- defaults/main.yml | 7 ++++++- templates/nginx-virthost.j2 | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/defaults/main.yml b/defaults/main.yml index 6fe4c2b..5a0371a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -103,8 +103,13 @@ nginx_logrotate_maxfilesize: "1G" nginx_logrotate_retention: "52" nginx_use_common_virthost: False +nginx_upstream_backends: [] +# - name: unicorn +# servers: +# - 127.0.0.1:4000 fail_timeout=0 +# # Virtualhost example -# nginx_virthosts: +nginx_virthosts: [] # - virthost_name: '{{ ansible_fqdn }}' # listen: '{{ http_port }}' # server_name: '{{ ansible_fqdn }}' diff --git a/templates/nginx-virthost.j2 b/templates/nginx-virthost.j2 index 3c383dc..ec59288 100644 --- a/templates/nginx-virthost.j2 +++ b/templates/nginx-virthost.j2 @@ -6,6 +6,14 @@ include /etc/nginx/snippets/nginx-websockets.conf; {% endif %} {% endif %} +{% for u_bk in nginx_upstream_backends %} +upstream {{ u_bk.name }} { + {% for srv in u_bk.servers %} + server {{ u_bk.srv }}; + {% endfor %} +} + +{% endfor %} server { listen {{ item.http_port | default ('80') }}; server_name {{ item.server_name }} {% if item.serveraliases is defined %}{{ item.serveraliases }}{% endif %};