tzkmx
10/10/2017 - 5:34 AM

SystemD Units to watch and force aliases to server_name in NginX, disallowing Plesk bloat

SystemD Units to watch and force aliases to server_name in NginX, disallowing Plesk bloat

#! /bin/bash

filename=/var/www/vhosts/system/$1/conf/nginx.conf

sed -i -e "/media[0-9]\.$1/d" $filename

for index in 4 3 2 1 ; do \
    sed -i -e "s@server_name $1;@\0\n\tserver_name media$index.$1;@" $filename ;
done
[Unit]
Description= Watches changes to Media enabled VirtualHost: %i.
Documentation= man:systemd.path

[Path]
PathChanged=/var/www/vhosts/system/%i/conf/nginx.conf

[Install]
WantedBy=multi-user.target
[Unit]
Description= Insert media server names in VirtualHost %i
Documentation= man:systemd.service

[Service]
Type=oneshot
ExecStart=/root/fix_media_vhosts.sh %i