From c53ab5d00827ddbdaa0a00027173c98df3db99aa Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Fri, 31 Jul 2015 00:38:16 +0200 Subject: [PATCH] New feature: custom location in vhost --- templates/etc/nginx/sites-available/_base.j2 | 14 +++++++++++++- tests/test.yml | 5 +++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/templates/etc/nginx/sites-available/_base.j2 b/templates/etc/nginx/sites-available/_base.j2 index 0f44620..2f55404 100644 --- a/templates/etc/nginx/sites-available/_base.j2 +++ b/templates/etc/nginx/sites-available/_base.j2 @@ -1,5 +1,6 @@ {% set __listen = item.listen | default(['80']) %} {% set __listen_ssl = item.listen_ssl | default(['443']) %} +{% set __location = item.location | default({}) %} # # {{ ansible_managed }} # @@ -30,7 +31,7 @@ server { {% block template_custom_location %} {% endblock %} - location ~ /\.ht { + location ~ /\.ht { deny all; } @@ -45,6 +46,17 @@ server { log_not_found off; } +{% if __location is iterable and __location | length > 0 %} + # --> Custom locations +{% for location, opts in __location.iteritems() %} + location {{ location }} { +{% for opt in opts %} + {{ opt }} +{% endfor %} + } +{% endfor %} # <-- Custom locations +{% endif %} + {% if item.use_access_log is defined and item.use_access_log %} access_log {{ nginx_log_dir }}/{{ item.name }}_access.log combined; {% else %} diff --git a/tests/test.yml b/tests/test.yml index e9dd56f..7f561ad 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -19,6 +19,11 @@ - 'test-alias.local' - 'test2-alias.local' template: '_base' + location: + '/test': + - 'return 403;' + '/gunther': + - 'return 404;' - name: - 'test-php.local' redirect_from: