add support to set location backends

This commit is contained in:
nd 2021-08-15 02:14:55 +02:00
parent 630a536c7f
commit fc5a1f4b2d
No known key found for this signature in database
GPG key ID: 21B5CD4DEE3670E9
2 changed files with 12 additions and 10 deletions

View file

@ -56,6 +56,10 @@ nginx_forcessl_vhost:
custom: custom:
- return 301 https://$host$request_uri - return 301 https://$host$request_uri
nginx_proxy_location:
match: /
backend: ~
phpinidefault: phpinidefault:
post_max_size: 64M post_max_size: 64M
upload_max_filesize: 64M upload_max_filesize: 64M

View file

@ -2,6 +2,7 @@
{% set vhost = {}|combine(nginx_vhosts_defaults, item.value, recursive=True) %} {% set vhost = {}|combine(nginx_vhosts_defaults, item.value, recursive=True) %}
{% set vhost_name = item.key %} {% set vhost_name = item.key %}
{% set vhost_headers = {}|combine(nginx.add_headers, vhost.add_headers) %} {% 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) %} {% macro nginx_listen(ips, port, options) %}
{% for ip in ips %} {% for ip in ips %}
@ -38,9 +39,13 @@ server {
{% endfor %} {% endfor %}
{% if vhost.backend %} {% for location in ( vhost.locations + vhost_proxy_location ) %}
location / { location {{ location.match }} {
proxy_pass {{ vhost.backend }}; {% if "alias" in location %}
alias {{ location.alias }};
{% endif %}
{% if location.backend|d(False) %}
proxy_pass {{ location.backend }};
# add proxy headers # add proxy headers
proxy_set_header Host {{ vhost.host }}; proxy_set_header Host {{ vhost.host }};
@ -72,13 +77,6 @@ server {
# no double headers # no double headers
proxy_hide_header Strict-Transport-Security; proxy_hide_header Strict-Transport-Security;
}
{% endif %}
{% for location in vhost.locations %}
location {{ location.match }} {
{% if "alias" in location %}
alias {{ location.alias }};
{% endif %} {% endif %}
{% for c in location.custom|default([]) %} {% for c in location.custom|default([]) %}
{{ c }}; {{ c }};