summaryrefslogtreecommitdiff
path: root/roles
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2021-04-03 19:29:46 +0200
committerChristian Pointner <equinox@spreadspace.org>2021-04-03 19:29:46 +0200
commit0cc14f6472bd45e6fbe1bd2a058da3eb58c5c923 (patch)
tree256658a5a9e70e057889495d187e38354960cd81 /roles
parentenable recording to glt-dione and glt-helene (diff)
nginx/vhost make static file templatemore generic
Diffstat (limited to 'roles')
-rw-r--r--roles/nginx/vhost/defaults/main.yml14
-rw-r--r--roles/nginx/vhost/templates/static-files-with-acme.conf.j230
2 files changed, 26 insertions, 18 deletions
diff --git a/roles/nginx/vhost/defaults/main.yml b/roles/nginx/vhost/defaults/main.yml
index 18c9a0b9..06f3dfb5 100644
--- a/roles/nginx/vhost/defaults/main.yml
+++ b/roles/nginx/vhost/defaults/main.yml
@@ -27,7 +27,13 @@
# acme: yes
# hostnames:
# - static.example.com
-# root: /srv/www/static
-# index: index.html
-# autoindex:
-# format: json
+# extra_directives: |-
+# add_header X-Example-Header "foo";
+# locations:
+# '/':
+# root: /srv/www/static
+# index: index.html
+# autoindex:
+# format: json
+# extra_directives: |-
+# add_header X-Example-Header "foo";
diff --git a/roles/nginx/vhost/templates/static-files-with-acme.conf.j2 b/roles/nginx/vhost/templates/static-files-with-acme.conf.j2
index 3dec7f27..09f22544 100644
--- a/roles/nginx/vhost/templates/static-files-with-acme.conf.j2
+++ b/roles/nginx/vhost/templates/static-files-with-acme.conf.j2
@@ -21,24 +21,26 @@ server {
ssl_certificate_key /var/lib/acme/live/{{ nginx_vhost.hostnames[0] }}/privkey;
include snippets/hsts.conf;
-{% if 'directives_extra' in nginx_vhost and 'server' in nginx_vhost.directives_extra %}
- {{ nginx_vhost.directives_extra.server | indent(4) }}
+{% if 'extra_directives' in nginx_vhost %}
+ {{ nginx_vhost.extra_directives | indent(4) }}
{% endif %}
- location / {
- root {{ nginx_vhost.root }};
-{% if 'index' in nginx_vhost %}
- index {{ nginx_vhost.index }};
-{% endif %}
-{% if 'autoindex' in nginx_vhost %}
+{% for path, location in nginx_vhost.locations.items() %}
+ location {{ path }} {
+ root {{ location.root }};
+{% if 'index' in location %}
+ index {{ location.index }};
+{% endif %}
+{% if 'autoindex' in location %}
autoindex on;
-{% if 'format' in nginx_vhost.autoindex %}
+{% if 'format' in location.autoindex %}
autoindex_format {{ nginx_vhost.autoindex.format }};
-{% endif %}
-{% endif %}
-{% if 'directives_extra' in nginx_vhost and 'location' in nginx_vhost.directives_extra %}
+{% endif %}
+{% endif %}
+{% if 'extra_directives' in location %}
- {{ nginx_vhost.directives_extra.location | indent(8) }}
-{% endif %}
+ {{ location.extra_directives | indent(8) }}
+{% endif %}
}
+{% endfor %}
}