Manages locations before "/"

pull/38/head
Emilien Mantel 2019-02-20 15:13:25 +01:00
parent 7959182bf8
commit 1437619475
3 changed files with 35 additions and 20 deletions

View File

@ -19,6 +19,8 @@ Common
- `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```. - `redirect_https`: (O) Boolean. Redirect HTTP to HTTPS. If "true", you _MUST_ set `proto` to ```['https']```.
- `location`: (O) Add new custom locations (it does not overwrite!) - `location`: (O) Add new custom locations (it does not overwrite!)
- `location_order`: (O) Due to non preditive `location` order, you can provide the good order (see test-location.local in [tests/test.yml](../tests/test.yml)). - `location_order`: (O) Due to non preditive `location` order, you can provide the good order (see test-location.local in [tests/test.yml](../tests/test.yml)).
- `location_before`: (O) Add new custom locations before generated location by template
- `location_order_before`: (O) Manages location order for `location_before`
- `more`: (O) Add more custom infos. - `more`: (O) Add more custom infos.
- `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP) - `upstream_params`: (O) Add upstream params (useful when you want to pass variables to PHP)
- `override_try_files`: (O) overrides default try\_files defined in template - `override_try_files`: (O) overrides default try\_files defined in template

View File

@ -5,9 +5,29 @@
{% set __http_proxy_protocol_port = item.http_proxy_protocol_port | default([]) %} {% set __http_proxy_protocol_port = item.http_proxy_protocol_port | default([]) %}
{% set __https_proxy_protocol_port = item.https_proxy_protocol_port | default([]) %} {% set __https_proxy_protocol_port = item.https_proxy_protocol_port | default([]) %}
{% set __location = item.location | default({}) %} {% set __location = item.location | default({}) %}
{% set __location_before = item.location_before | default({}) %}
{% set __headers = item.headers | default(nginx_servers_default_headers) %} {% set __headers = item.headers | default(nginx_servers_default_headers) %}
{% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %} {% set __ssl_name = item.ssl_name | default(item.name if item.name is string else item.name[0]) %}
{% set __location_order = item.location_order | default(__location.keys()) %} {% set __location_order = item.location_order | default(__location.keys()) %}
{% set __location_order_before = item.location_order_before | default(__location_before.keys()) %}
{% macro locations(list, order) %}
{% if order | length > 0 %}
# --> Custom locations
{% for location in order %}
location {{ location }} {
{% set opts = list[location] %}
{% for opt in opts %}
{% if opt.htpasswd is defined %}
{{ htpasswd(opt.htpasswd, 2) }}
{% else %}
{{ opt }}
{% endif %}
{% endfor %}
}
{% endfor %}
# <-- Custom locations
{% endif %}
{% endmacro %}
{% macro htpasswd(htpasswd_name, indent=1) -%} {% macro htpasswd(htpasswd_name, indent=1) -%}
{%- if htpasswd_name != false %} {%- if htpasswd_name != false %}
{%- for ht in nginx_htpasswd if ht.name == htpasswd_name %} {%- for ht in nginx_htpasswd if ht.name == htpasswd_name %}
@ -88,6 +108,8 @@ server {
# <-- Custom headers # <-- Custom headers
{% endblock %} {% endblock %}
{{ locations(__location_before, __location_order_before) }}
{% if not __location.has_key('/') %} {% if not __location.has_key('/') %}
location / { location / {
{% block template_try_files %} {% block template_try_files %}
@ -101,19 +123,7 @@ server {
{% block template_custom_location %} {% block template_custom_location %}
{% endblock %} {% endblock %}
{% if __location_order | length > 0 %} {{ locations(__location, __location_order) }}
# --> Custom locations
{% for location in __location_order %}
location {{ location }} {
{% set opts = __location[location] %}
{% for opt in opts %}
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
{{ opt }}
{% endif %}
{% endfor %}
}
{% endfor %} # <-- Custom locations
{% endif %}
{% block template_local_content %} {% block template_local_content %}
{% if item.manage_local_content is not defined or item.manage_local_content %} {% if item.manage_local_content is not defined or item.manage_local_content %}

View File

@ -164,9 +164,10 @@
- 'deny all;' - 'deny all;'
- name: 'test-htpasswd.local' - name: 'test-htpasswd.local'
template: '_base' template: '_base'
location: location_before:
'/hello': '/hello':
- htpasswd: 'hello' - htpasswd: 'hello'
location:
'/public': '/public':
- htpasswd: false - htpasswd: false
use_error_log: true use_error_log: true
@ -175,20 +176,22 @@
htpasswd: 'hello' htpasswd: 'hello'
- name: 'test-location.local' - name: 'test-location.local'
template: '_base' template: '_base'
location_before:
'/b':
- 'alias /var/tmp;'
'/c':
- 'alias /var/tmp;'
location: location:
'/': '/':
- 'alias /var/tmp;' - 'alias /var/tmp;'
'/a': '/a':
- 'alias /var/tmp;' - 'alias /var/tmp;'
'/b': location_order_before:
- 'alias /var/tmp;' - '/b'
'/c': - '/c'
- 'alias /var/tmp;'
location_order: location_order:
- '/' - '/'
- '/a' - '/a'
- '/b'
- '/c'
- name: 'test-php.local' - name: 'test-php.local'
php_version: "{{ nginx_php.1.version if nginx_php.1 is defined else nginx_php.0.version }}" php_version: "{{ nginx_php.1.version if nginx_php.1 is defined else nginx_php.0.version }}"
upstream_params: upstream_params: