2020-08-30 11:36:48 +02:00
|
|
|
directories = {
|
|
|
|
'/etc/nginx/sites': {
|
|
|
|
'purge': True,
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-13 13:35:02 +01:00
|
|
|
'/var/www': {},
|
2020-08-30 11:36:48 +02:00
|
|
|
}
|
|
|
|
|
2020-04-13 09:52:26 +02:00
|
|
|
files = {
|
|
|
|
'/etc/nginx/nginx.conf': {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'context': node.metadata['nginx'],
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-10-31 13:00:38 +01:00
|
|
|
'/etc/nginx/fastcgi.conf': {
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-06-01 13:35:54 +02:00
|
|
|
'/etc/nginx/sites/stub_status': {
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
},
|
2020-11-10 10:57:04 +01:00
|
|
|
'/usr/local/share/icinga/plugins/check_nginx_status': {
|
|
|
|
'mode': '0755',
|
|
|
|
},
|
2020-04-13 09:52:26 +02:00
|
|
|
}
|
|
|
|
|
2020-10-31 10:18:40 +01:00
|
|
|
actions = {
|
|
|
|
'nginx-generate-dhparam': {
|
|
|
|
'command': 'openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048',
|
|
|
|
'unless': 'test -f /etc/ssl/certs/dhparam.pem',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-04-13 09:52:26 +02:00
|
|
|
svc_systemd = {
|
|
|
|
'nginx': {
|
|
|
|
'needs': {
|
2020-10-31 10:18:40 +01:00
|
|
|
'action:nginx-generate-dhparam',
|
2020-04-13 09:52:26 +02:00
|
|
|
'pkg_apt:nginx',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-06-01 10:52:52 +02:00
|
|
|
|
2021-02-20 14:25:27 +01:00
|
|
|
# Always redirect all traffic to HTTPS, except if there is only one
|
|
|
|
# vhost and this vhost has ssl disabled.
|
|
|
|
install_port80_redirect = True
|
|
|
|
if len(node.metadata.get('nginx/vhosts', {})) == 1:
|
|
|
|
vhost_name = list(node.metadata['nginx']['vhosts'].keys())[0]
|
|
|
|
if node.metadata.get('nginx/vhosts/{}/ssl'.format(vhost_name), 'letsencrypt') == False:
|
|
|
|
install_port80_redirect = False
|
2020-09-20 14:36:43 +02:00
|
|
|
|
2021-02-20 14:25:27 +01:00
|
|
|
if install_port80_redirect:
|
2020-09-20 14:36:43 +02:00
|
|
|
files['/etc/nginx/sites/000-port80.conf'] = {
|
|
|
|
'source': 'port80.conf',
|
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-02-18 18:12:25 +01:00
|
|
|
for vhost, config in node.metadata.get('nginx/vhosts', {}).items():
|
2020-10-31 10:30:07 +01:00
|
|
|
if not 'domain' in config:
|
|
|
|
config['domain'] = vhost
|
|
|
|
|
|
|
|
files['/etc/nginx/sites/{}'.format(vhost)] = {
|
2020-06-01 10:52:52 +02:00
|
|
|
'source': 'site_template',
|
|
|
|
'content_type': 'mako',
|
2020-10-31 10:41:33 +01:00
|
|
|
'context': {
|
|
|
|
'vhost': vhost,
|
2021-02-18 18:12:25 +01:00
|
|
|
'php_version': node.metadata.get('php/version', ''),
|
2020-10-31 10:41:33 +01:00
|
|
|
**config,
|
|
|
|
},
|
2020-09-20 14:36:43 +02:00
|
|
|
'needs': set(),
|
2020-06-01 10:52:52 +02:00
|
|
|
'triggers': {
|
|
|
|
'svc_systemd:nginx:restart',
|
|
|
|
},
|
|
|
|
}
|
2020-09-20 14:36:43 +02:00
|
|
|
|
2020-10-18 18:55:00 +02:00
|
|
|
if not 'webroot' in config:
|
2020-11-12 22:59:46 +01:00
|
|
|
directories['/var/www/{}'.format(vhost)] = {}
|
|
|
|
|
|
|
|
if node.has_bundle('zfs'):
|
|
|
|
directories['/var/www/{}'.format(vhost)]['needs'] = {
|
|
|
|
'bundle:zfs',
|
|
|
|
}
|
|
|
|
|
|
|
|
directories['/var/www/{}'.format(vhost)].update(config.get('webroot_config', {}))
|
2020-10-18 18:55:00 +02:00
|
|
|
|
2021-02-20 14:25:27 +01:00
|
|
|
if config.get('ssl', 'letsencrypt') == 'letsencrypt':
|
2021-02-20 13:52:20 +01:00
|
|
|
files['/etc/nginx/sites/{}'.format(vhost)]['needs'].add('action:letsencrypt_ensure-some-certificate_{}'.format(config['domain']))
|