roles/nginx: smarter setting of document root

This commit is contained in:
Alan Orth 2025-03-29 19:34:53 +03:00
parent 84db337fea
commit 7f9b06af9c
Signed by: alanorth
GPG Key ID: 0FB860CC9C45B1B9

View File

@ -8,6 +8,12 @@
{% set has_wordpress = item.has_wordpress | default(false) %}
{% set needs_php = item.needs_php | default(false) %}
{% set has_gitea = item.has_gitea | default(false) %}
{# Allow sites to override the document root #}
{% if item.document_root is defined %}
{% set document_root = item.document_root %}
{% else %}
{% set document_root = (nginx_root_prefix, domain_name) | ansible.builtin.path_join %}
{% endif %}
# http -> https vhost
server {
@ -29,12 +35,7 @@ server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
{# Allow sites to override the nginx document root #}
{% if item.document_root is defined %}
root {{ item.document_root }};
{% else %}
root {{ nginx_root_prefix }}/{{ domain_name }};
{% endif %}
root {{ document_root }};
{# will only work if the TLS cert covers the domain + aliases, like example.com and www.example.com #}
server_name {{ domain_name }} {{ domain_aliases }};