From fc5a1f4b2d1dde6e99ee80bc9dc932a0cc32415c Mon Sep 17 00:00:00 2001 From: nd Date: Sun, 15 Aug 2021 02:14:55 +0200 Subject: [PATCH] add support to set location backends --- defaults/main.yml | 4 ++++ templates/vhost.conf.j2 | 18 ++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index 4479272..a5f9df1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -56,6 +56,10 @@ nginx_forcessl_vhost: custom: - return 301 https://$host$request_uri +nginx_proxy_location: + match: / + backend: ~ + phpinidefault: post_max_size: 64M upload_max_filesize: 64M diff --git a/templates/vhost.conf.j2 b/templates/vhost.conf.j2 index ee4e200..f93b175 100644 --- a/templates/vhost.conf.j2 +++ b/templates/vhost.conf.j2 @@ -2,6 +2,7 @@ {% set vhost = {}|combine(nginx_vhosts_defaults, item.value, recursive=True) %} {% set vhost_name = item.key %} {% set vhost_headers = {}|combine(nginx.add_headers, vhost.add_headers) %} +{% set vhost_proxy_location = {}|combine(nginx_proxy_location, {'backend': vhost.backend }) if vhost.backend|d(False) else [] %} {% macro nginx_listen(ips, port, options) %} {% for ip in ips %} @@ -38,9 +39,13 @@ server { {% endfor %} - {% if vhost.backend %} - location / { - proxy_pass {{ vhost.backend }}; + {% for location in ( vhost.locations + vhost_proxy_location ) %} + location {{ location.match }} { + {% if "alias" in location %} + alias {{ location.alias }}; + {% endif %} + {% if location.backend|d(False) %} + proxy_pass {{ location.backend }}; # add proxy headers proxy_set_header Host {{ vhost.host }}; @@ -72,13 +77,6 @@ server { # no double headers proxy_hide_header Strict-Transport-Security; - } - {% endif %} - - {% for location in vhost.locations %} - location {{ location.match }} { - {% if "alias" in location %} - alias {{ location.alias }}; {% endif %} {% for c in location.custom|default([]) %} {{ c }};