bundles/nginx: use metadata reactor to determine index files

This commit is contained in:
Franzi 2020-10-31 10:41:33 +01:00
parent 3ee570a47a
commit e2d8923dee
Signed by: kunsi
GPG key ID: 12E3D2136B818350
4 changed files with 30 additions and 6 deletions

View file

@ -1,7 +1,7 @@
server { server {
server_name ${domain}; server_name ${domain};
root ${webroot if webroot else '/var/www/{}/'.format(domain)}; root ${webroot if webroot else '/var/www/{}/'.format(vhost)};
index ${index if index else 'index.html index.htm'}; index ${' '.join(index)};
% if node.metadata['nginx']['use_ssl_for_all_connections']: % if node.metadata['nginx']['use_ssl_for_all_connections']:
listen 443 ssl http2; listen 443 ssl http2;

View file

@ -58,7 +58,10 @@ for vhost, config in node.metadata.get('nginx', {}).get('vhosts', {}).items():
files['/etc/nginx/sites/{}'.format(vhost)] = { files['/etc/nginx/sites/{}'.format(vhost)] = {
'source': 'site_template', 'source': 'site_template',
'content_type': 'mako', 'content_type': 'mako',
'context': config, 'context': {
'vhost': vhost,
**config,
},
'needs': set(), 'needs': set(),
'triggers': { 'triggers': {
'svc_systemd:nginx:restart', 'svc_systemd:nginx:restart',

View file

@ -46,3 +46,27 @@ def letsencrypt(metadata):
}, },
}, },
} }
@metadata_reactor
def index_files(metadata):
vhosts = {}
for vhost, config in metadata.get('nginx/vhosts', {}).items():
vhosts[vhost] = {
'index': [
'index.html',
'index.htm',
],
}
if config.get('php', False):
# If we're using PHP, make sure index.php is tried first
vhosts[vhost]['index'].insert(0, 'index.php')
return {
'nginx': {
'vhosts': vhosts,
},
}

View file

@ -192,7 +192,6 @@ nodes['htz.ex42-1048908'] = {
}, },
'postfixadmin.mx0.kunbox.net': { 'postfixadmin.mx0.kunbox.net': {
'webroot': '/srv/postfixadmin/public/', 'webroot': '/srv/postfixadmin/public/',
'index': 'index.php',
'php': True, # FIXME this assumes php 7.3 is installed and configured already 'php': True, # FIXME this assumes php 7.3 is installed and configured already
}, },
'rspamd.mx0.kunbox.net': { 'rspamd.mx0.kunbox.net': {
@ -217,11 +216,9 @@ nodes['htz.ex42-1048908'] = {
}, },
}, },
'webmail.mx0.kunbox.net': { 'webmail.mx0.kunbox.net': {
'index': 'index.php',
'php': True, 'php': True,
}, },
'wiki.franzi.business': { 'wiki.franzi.business': {
'index': 'doku.php',
'extras': True, 'extras': True,
'php': True, 'php': True,
'webroot_config': { 'webroot_config': {