New feature: provide location order (#24 related)

pull/27/head 1.3.3
Emilien Mantel 2016-11-23 11:43:13 +01:00
parent de71e1bdcc
commit 5b0977567c
4 changed files with 18 additions and 4 deletions

View File

@ -18,6 +18,7 @@ Common
- `redirect_to_code`: Redirect code (default: 302) - `redirect_to_code`: Redirect code (default: 302)
- `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)).
- `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,6 +5,7 @@
{% set __location = item.location | default({}) %} {% set __location = item.location | default({}) %}
{% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %} {% set __headers = item.headers | default({'X-Frame-Options': 'DENY always', 'X-Content-Type-Options': 'nosniff always' }) %}
{% 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()) %}
{% macro htpasswd(htpasswd_name, indent=1) -%} {% macro htpasswd(htpasswd_name, indent=1) -%}
{% for ht in nginx_htpasswd if ht.name == htpasswd_name %} {% for ht in nginx_htpasswd if ht.name == htpasswd_name %}
{{ "\t" * indent }}auth_basic "{{ ht.description }}"; {{ "\t" * indent }}auth_basic "{{ ht.description }}";
@ -84,10 +85,11 @@ server {
{% block template_custom_location %} {% block template_custom_location %}
{% endblock %} {% endblock %}
{% if __location is iterable and __location | length > 0 %} {% if __location_order | length > 0 %}
# --> Custom locations # --> Custom locations
{% for location, opts in __location.iteritems() %} {% for location in __location_order %}
location {{ location }} { location {{ location }} {
{% set opts = __location[location] %}
{% for opt in opts %} {% for opt in opts %}
{% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %} {% if opt.htpasswd is defined %}{{ htpasswd(opt.htpasswd, 2) }}{% else %}
{{ opt }} {{ opt }}

View File

@ -155,6 +155,17 @@
location: location:
'/': '/':
- 'alias /var/tmp;' - 'alias /var/tmp;'
'/a':
- 'alias /var/tmp;'
'/b':
- 'alias /var/tmp;'
'/c':
- 'alias /var/tmp;'
location_order:
- '/'
- '/a'
- '/b'
- '/c'
- name: 'test-php.local' - name: 'test-php.local'
php_version: "{{ '7.0' if nginx_php70 else '5.6' }}" php_version: "{{ '7.0' if nginx_php70 else '5.6' }}"
upstream_params: upstream_params: