reworked getopts

This commit is contained in:
Matthew Saunders Brown 2021-10-05 11:33:24 -07:00
parent b3e918f252
commit e8570e1a82
20 changed files with 399 additions and 513 deletions

View File

@ -12,84 +12,64 @@ help()
thisfilename=$(basename -- "$0")
echo "Add virtualhost to this server."
echo ""
echo "usage: $thisfilename virtualhost username [OPTIONS]"
echo "usage: $thisfilename -d <domain> -u <username> [-h]"
echo ""
echo " -h Print this help."
echo ""
echo " Username must already exist. If need be run vhost-user-add.sh first."
echo " -d <domain> Domain name to add as a VirtualHost. www. subdomain is automatically aliased."
echo " -u <username> Username to install VirtualHost for. Username must already exist."
echo " If need be run vhost-user-add.sh first."
echo " Or use vhost-deploy.sh instead to automatically generate username."
exit
}
# check for and set virtualhost & username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
# virtualhost
if vhost::validate_domain $1; then
virtualhost="${1,,}"
else
echo "ERROR: $1 is not a valid domain name."
exit 1
fi
# username
if [ -n "$2" ]; then
if [ $2 == "-h" ]; then
help
else
username="${2,,}"
fi
else
echo "username not set"
exit 1
fi
# last check for -h
if [ -n "$3" ]; then
if [ $3 == "-h" ]; then
help
fi
fi
fi
else
help
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
if [ ! -d /home/$username ]; then
# check for username
if [[ -z $username ]]; then
echo "username is required"
exit
fi
if [[ ! -d /home/$username ]]; then
echo "home dir for $username does not exist"
exit 1
fi
if [ -d /srv/www/$virtualhost ]; then
chown $username:$username /srv/www/$virtualhost
chmod 755 /srv/www/$virtualhost
if [[ -d /srv/www/$domain ]]; then
chown $username:$username /srv/www/$domain
chmod 755 /srv/www/$domain
else
install -d -o $username -g $username -m 755 /srv/www/$virtualhost
install -d -o $username -g $username -m 755 /srv/www/$domain
fi
if [ -d /srv/www/$virtualhost/html ]; then
chown $username:$username /srv/www/$virtualhost/html
chmod 755 /srv/www/$virtualhost/html
if [[ -d /srv/www/$domain/html ]]; then
chown $username:$username /srv/www/$domain/html
chmod 755 /srv/www/$domain/html
else
install -d -o $username -g $username -m 755 /srv/www/$virtualhost/html
install -d -o $username -g $username -m 755 /srv/www/$domain/html
fi
if [ ! -e /home/$username/$virtualhost ]; then
ln -s /srv/www/$virtualhost /home/$username/$virtualhost
chown -h $username:$username /home/$username/$virtualhost
if [[ ! -e /home/$username/$domain ]]; then
ln -s /srv/www/$domain /home/$username/$domain
chown -h $username:$username /home/$username/$domain
fi
if [ -d /usr/jails/$username ]; then
if [ ! -d /usr/jails/$username/srv/www/$virtualhost ]; then
install -d -o $username -g $username -m 755 /usr/jails/$username/srv/www/$virtualhost
mount --bind /srv/www/$virtualhost /usr/jails/$username/srv/www/$virtualhost
echo "/srv/www/$virtualhost /usr/jails/$username/srv/www/$virtualhost none bind 0 0" >> /etc/fstab.jails
if [[ -d /usr/jails/$username ]]; then
if [[ ! -d /usr/jails/$username/srv/www/$domain ]]; then
install -d -o $username -g $username -m 755 /usr/jails/$username/srv/www/$domain
mount --bind /srv/www/$domain /usr/jails/$username/srv/www/$domain
echo "/srv/www/$domain /usr/jails/$username/srv/www/$domain none bind 0 0" >> /etc/fstab.jails
fi
fi
# php-fpm pool
vhost::set-phpVersion
if [ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]; then
if [[ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then
# create /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "[$username]" > /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "user = $username" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
@ -103,7 +83,7 @@ if [ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]; then
echo "pm = ondemand" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "pm.max_children = 12" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "pm.process_idle_timeout = 3s;" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -fwebmaster@$virtualhost" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
echo "php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -fwebmaster@$domain" >> /etc/php/$phpVersion/fpm/pool.d/$username.conf
# restart php$phpVersion-fpm
if systemctl is-active --quiet php$phpVersion-fpm ; then
if /usr/sbin/php-fpm$phpVersion -t >/dev/null 2>&1 ; then
@ -115,4 +95,4 @@ if [ ! -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]; then
fi
# create & enable apache config
/usr/local/bin/vhost-enable.sh VHostHTTP $virtualhost
/usr/local/bin/vhost-enable.sh VHostHTTP $domain

View File

@ -12,76 +12,74 @@ help()
thisfilename=$(basename -- "$0")
echo "Removes virtualhost from server."
echo ""
echo "usage: $thisfilename virtualhost [OPTIONS]"
echo "usage: $thisfilename -d <domain> [-h]"
echo ""
echo " -d <domain> Domain name of VirtualHost to remove."
echo " -h Print this help."
exit
}
# check for and set virtualhost
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
virtualhost="${1,,}"
fi
else
help
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
# remove virtualhost dir
if [ ! -d /srv/www/$virtualhost ]; then
# check for virtualhost dir
if [[ ! -d /srv/www/$domain ]]; then
echo "virtualhost dir does not exist"
exit 1
fi
username=$(stat -c '%U' /srv/www/$virtualhost)
username=$(stat -c '%U' /srv/www/$domain)
# disable the apache conf and reload apache
if [ -h /etc/apache2/sites-enabled/$virtualhost.conf ]; then
a2dissite --quiet $virtualhost
if [[ -h /etc/apache2/sites-enabled/$domain.conf ]]; then
a2dissite --quiet $domain
systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
fi
# remove the apache config
if [ -f /etc/apache2/sites-available/$virtualhost.conf ]; then
rm /etc/apache2/sites-available/$virtualhost.conf
if [[ -f /etc/apache2/sites-available/$domain.conf ]]; then
rm /etc/apache2/sites-available/$domain.conf
fi
# remove varnish config
if [ -f /etc/varnish/sites.d/$virtualhost.vcl ]; then
rm /etc/varnish/sites.d/$virtualhost.vcl
if [[ -f /etc/varnish/sites.d/$domain.vcl ]]; then
rm /etc/varnish/sites.d/$domain.vcl
/usr/local/bin/vhost-varnish-update-sites.sh
# don't bother to restart varnish as it will clear cache unnecessarily
fi
# if virtualhost is mounted in a jail, unmount it
if grep -q "^/dev/sda /usr/jails/$username/srv/www/$virtualhost " /etc/mtab; then
umount /usr/jails/$username/srv/www/$virtualhost
if grep -q "^/dev/sda /usr/jails/$username/srv/www/$domain " /etc/mtab; then
umount /usr/jails/$username/srv/www/$domain
fi
# if virtualhost mount in fstab.jails exists remove it
if grep -q "/usr/jails/$username/srv/www/$virtualhost" /etc/fstab.jails; then
sed -i "\|/usr/jails/$username/srv/www/$virtualhost|d" /etc/fstab.jails
if grep -q "/usr/jails/$username/srv/www/$domain" /etc/fstab.jails; then
sed -i "\|/usr/jails/$username/srv/www/$domain|d" /etc/fstab.jails
fi
# if virtualhost symlink exists in jail remove it
if [ -h /usr/jails/$username/home/$username/$virtualhost ]; then
unlink /usr/jails/$username/home/$username/$virtualhost
if [[ -h /usr/jails/$username/home/$username/$domain ]]; then
unlink /usr/jails/$username/home/$username/$domain
fi
# if virtualhost symlink exists in home dir remove it
if [ -h /home/$username/$virtualhost ]; then
unlink /home/$username/$virtualhost
if [[ -h /home/$username/$domain ]]; then
unlink /home/$username/$domain
fi
# if virtualhost dir exists in jail remove it
if [ -d /usr/jails/$username/srv/www/$virtualhost ]; then
rm -r /usr/jails/$username/srv/www/$virtualhost
if [[ -d /usr/jails/$username/srv/www/$domain ]]; then
rm -r /usr/jails/$username/srv/www/$domain
fi
# remove virtualhost dir
if [ -d /srv/www/$virtualhost ]; then
rm -r /srv/www/$virtualhost
if [[ -d /srv/www/$domain ]]; then
rm -r /srv/www/$domain
fi

View File

@ -12,97 +12,60 @@ help()
thisfilename=$(basename -- "$0")
echo "Add virtualhost to this server, including shell user and MySQL database."
echo ""
echo "usage: $thisfilename virtualhost [OPTIONS]"
echo "usage: $thisfilename -d <domain> [OPTIONS]"
echo ""
echo " -h Print this help."
echo " -u USERNAME Username to use for this virtualhost. Optional, defaults to first 8 alphanumeric characters of virtualhost."
echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
echo " -d <domain> Domain name of VirtualHost to remove."
echo " -u <username> Username to use for this virtualhost. Optional, defaults to first 8 alphanumeric characters of virtualhost."
echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -j Whether or not to jail the user. Optional, default is to not jail user."
exit
}
# check for and set virtualhost
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
elif vhost::validate_domain $1; then
virtualhost="${1,,}"
shift
else
echo "ERROR: Invalid virtualhost: $1"
exit 1
fi
else
help
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
while getopts "hu:p:j" opt; do
case "${opt}" in
h )
help
exit;;
u )
username=${OPTARG}
;;
p )
password=${OPTARG}
;;
j )
jail=true
;;
\? )
echo "Invalid option: $OPTARG"
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument"
exit 1
;;
esac
done
# check virtualhost
if [ ! -n "$virtualhost" ]; then
echo "virtualhost not set"
exit 1
fi
if [ -d /srv/www/$virtualhost ] || [ -f /etc/apache2/sites-available/$virtualhost.conf ]; then
echo "virtualhost for $virtualhost already installed"
if [[ -d /srv/www/$domain ]] || [[ -f /etc/apache2/sites-available/$domain.conf ]]; then
echo "virtualhost for $domain already installed"
exit 1
fi
# check for and set username
if [ ! -n "$username" ]; then
username=`echo $virtualhost | sed 's|\.||'`
if [[ -z "$username" ]]; then
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:8}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:7}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:6}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:5}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:9}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:10}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:11}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo $domain | sed 's|\.||'`
username=`echo ${username:0:12}`
if grep -q "^$username:" /etc/passwd; then
echo "trouble setting unique username, specify '-u USERNAME' to use an existing username"
@ -119,19 +82,19 @@ fi
if ! grep -q "^$username:" /etc/passwd; then
# check for and set password
if [ ! -n "$password" ]; then
if [[ -z "$password" ]]; then
password=`/usr/bin/pwgen 12 1`
fi
# add user
/usr/local/bin/vhost-user-add.sh $username -p "$password"
# if jail option is set then jail user
if [[ $jail = true ]]; then
if [[ -n $jail ]]; then
/usr/local/bin/vhost-user-jail.sh $username > /dev/null 2>&1
fi
fi
# add virtualhost
/usr/local/bin/vhost-add.sh $virtualhost $username > /dev/null 2>&1
/usr/local/bin/vhost-add.sh $domain $username > /dev/null 2>&1
# add mysql database
/usr/local/bin/vhost-mysql-db-add.sh $virtualhost > /dev/null 2>&1
/usr/local/bin/vhost-mysql-db-add.sh $domain > /dev/null 2>&1

View File

@ -12,40 +12,41 @@ help()
thisfilename=$(basename -- "$0")
echo "Remove virtualhost and associated user & database & db user from this server."
echo ""
echo "usage: $thisfilename virtualhost"
echo "usage: $thisfilename -d <domain>"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to remove."
exit
}
# check for and set virtualhost
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
elif [ ! -d /srv/www/$1 ]; then
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
# check that virtualhost dir exists
if [[ ! -d /srv/www/$domain ]]; then
echo "virtualhost dir does not exist"
exit 1
else
virtualhost="${1,,}"
fi
else
help
fi
# check for database and delete if it exists
database=${virtualhost//./dot}
database=${domain//./dot}
database=${database//-/dash}
if [ -d /var/lib/mysql/$database ]; then
/usr/local/bin/vhost-mysql-db-del.sh $virtualhost
if [[ -d /var/lib/mysql/$database ]]; then
/usr/local/bin/vhost-mysql-db-del.sh $domain
fi
# get & set username for this virtualhost
username=$(stat -c '%U' /srv/www/$virtualhost)
username=$(stat -c '%U' /srv/www/$domain)
# check for a delete varnish config
# del virtualhost files & configs
/usr/local/bin/vhost-del.sh $virtualhost
/usr/local/bin/vhost-del.sh $domain
# check for any remaining virtualhosts before deleting user
# same check is done in vhost-user-del.sh
@ -53,11 +54,11 @@ username=$(stat -c '%U' /srv/www/$virtualhost)
vhost::set-virtualhostArray
for v in "${virtualhostArray[@]}"
do
if [ $(stat -c '%U' /srv/www/$v) = $username ]; then
if [[ $(stat -c '%U' /srv/www/$v) = $username ]]; then
existingvirtualhosts=true
fi
done
if [ -n "$existingvirtualhosts" ]; then
if [[ -n "$existingvirtualhosts" ]]; then
/usr/local/bin/vhost-user-del.sh $username
fi

View File

@ -12,24 +12,21 @@ help()
thisfilename=$(basename -- "$0")
echo "Disable Apache config for specified virtualhost."
echo ""
echo "usage: $thisfilename virtualhost"
echo "usage: $thisfilename -d <domain>"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to remove."
exit
}
# check for and set virtualhost
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
virtualhost="${1,,}"
fi
else
echo "virtualhost not set"
exit 1
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
if [[ -h /etc/apache2/sites-enabled/$virtualhost.conf ]]; then
a2dissite --quiet $virtualhost && systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
if [[ -h /etc/apache2/sites-enabled/$domain.conf ]]; then
a2dissite --quiet $domain && systemctl --quiet is-active apache2 && systemctl --quiet reload apache2
fi

View File

@ -12,9 +12,12 @@ help()
thisfilename=$(basename -- "$0")
echo "Enable Apache config for virtualhost."
echo ""
echo "usage: $thisfilename macro_name vhost [subdomain|alias]"
echo "usage: $thisfilename -d <domain> -m <macro> [-o <subdomain>|<alias>|<redirect_url>] [-h]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to remove."
echo " -m <macro> Name of Apache macro to apply."
echo " -o <option> Subdomain or Alias or Redirect URL if specified macro requires one."
echo ""
echo " Available Apache Macros:"
echo ""
@ -32,101 +35,96 @@ help()
echo " Usage examples:"
echo " vhost-enable.sh VHostHTTPS example.com"
echo " vhost-enable.sh VHostSubdomainHTTPS example.com staging"
echo " vhost-enable.sh VHostAliasHTTPS example.com existingsite"
echo " vhost-enable.sh -d example.com(exising Vhost) -m VHostAliasHTTPS -o alias(site to alias to existing vhost)"
echo " vhost-enable.sh VMailHTTPS mail.example.com"
echo " vhost-enable.sh RedirectHTTPS example.com https://my.newsite.com/path/page.html"
echo ""
echo " Apache mod_macro config will look like:"
echo ' Use VHostHTTP $vhost $username'
echo ' Use VHostHTTPS $vhost $username'
echo ' Use VHostHTTPSVarnish $vhost $username'
echo ' Use VHostSubdomainHTTP $vhost $username $subdomain'
echo ' Use VHostSubdomainHTTPS $vhost $username $subdomain'
echo ' Use VHostSubdomainHTTPSVarnish $vhost $username $subdomain'
echo ' Use VHostAliasHTTP $vhost $username $alias'
echo ' Use VHostAliasHTTPS $vhost $username $alias'
echo ' Use VHostAliasHTTPSVarnish $vhost $username $alias'
echo ' Use VMailHTTPS $vhost'
echo ' Use RedirectHTTP $vhost $redirect'
echo ' Use RedirectHTTPS $vhost $redirect'
echo ' Use VHostHTTP $domain $username'
echo ' Use VHostHTTPS $domain $username'
echo ' Use VHostHTTPSVarnish $domain $username'
echo ' Use VHostSubdomainHTTP $domain $username $subdomain'
echo ' Use VHostSubdomainHTTPS $domain $username $subdomain'
echo ' Use VHostSubdomainHTTPSVarnish $domain $username $subdomain'
echo ' Use VHostAliasHTTP $domain $username $alias'
echo ' Use VHostAliasHTTPS $domain $username $alias'
echo ' Use VHostAliasHTTPSVarnish $domain $username $alias'
echo ' Use VMailHTTPS $domain'
echo ' Use RedirectHTTP $domain $redirect'
echo ' Use RedirectHTTPS $domain $redirect'
echo ''
echo ' $username is autodetected from vhost dir ownership'
echo " See /etc/apache2/mods-available/macro.conf for macro details."
echo ""
exit
}
macro_array=($(grep Macro /etc/apache2/mods-available/macro.conf |cut -d ' ' -f 2|grep -v Macro))
macro_vhost_line="Use"
# check for and set macro & vhost
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
# check for and set macro
macro_name=$1
if [[ " ${macro_array[@]} " =~ " ${macro_name} " ]]; then
macro_vhost_line="$macro_vhost_line $macro_name"
vhost:getoptions "$@"
# check for macro
if [[ -n $macro ]]; then
if [[ " ${macro_array[@]} " =~ " ${macro} " ]]; then
macro_vhost_line="$macro_vhost_line $macro"
else
echo "invalid macro name"
exit 1
fi
# check for and set vhost
if [ -n "$2" ]; then
vhost=$2
macro_vhost_line="$macro_vhost_line $vhost"
vhost_conf="$vhost.conf"
else
echo "vhost not set"
echo
help
fi
echo "macro is required"
exit
fi
# check for domain (virtualhost)
if [[ -n $domain ]]; then
macro_vhost_line="$macro_vhost_line $domain"
vhost_conf="$domain.conf"
else
help
echo "domain is required"
exit
fi
# set username for all VHost macros
if [[ "$macro_name" == *"VHost"* ]]; then
if [[ "$macro" == *"VHost"* ]]; then
# check for vhost dir
if [ -d "/srv/www/$vhost" ]; then
if [[ -d "/srv/www/$domain" ]]; then
# get and set $username
username=$(stat -c '%U' /srv/www/$vhost)
username=$(stat -c '%U' /srv/www/$domain)
macro_vhost_line="$macro_vhost_line $username"
else
echo "vhost dir for $vhost does not exist"
echo "VirtualHost dir for $domain does not exist."
exit 1
fi
# check for and set Subdomain
if [[ "$macro_name" == *"Subdomain"* ]]; then
if [ -n "$3" ]; then
subdomain=$3
if [[ "$macro" == *"Subdomain"* ]]; then
if [[ -n $option ]]; then
subdomain=$option
# make sure Subdomain isn't already installed
if [ -d "/srv/www/$subdomain.$vhost" ]; then
echo "$subdomain.$vhost is already installed as it's own vhost"
if [[ -d "/srv/www/$subdomain.$domain" ]]; then
echo "$subdomain.$domain is already installed as it's own VirtualHost."
exit 1
fi
if [ ! -d "/srv/www/$vhost/$subdomain" ]; then
echo "subdomain directory (/srv/www/$vhost/$subdomain) does not exist"
if [[ ! -d "/srv/www/$domain/$subdomain" ]]; then
echo "Subdomain directory (/srv/www/$domain/$subdomain) does not exist"
exit 1
fi
macro_vhost_line="$macro_vhost_line $subdomain"
vhost_conf="$subdomain.$vhost_conf"
vhost_conf="$subdomain.$domain_conf"
else
echo "subdomain not set"
echo "subdomain (-o OPTION) not set"
exit 1
fi
fi
# check for and set Alias
if [[ "$macro_name" == *"Alias"* ]]; then
if [ -n "$3" ]; then
if [[ "$macro" == *"Alias"* ]]; then
if [ -n $option ]; then
alias=$option
# make sure Alias domain isn't already installed as it's own vhost
if [ -d "/srv/www/$vhost" ]; then
if [ -d "/srv/www/$alias" ]; then
echo "$alias is already installed as it's own vhost"
exit 1
else
alias=$3
macro_vhost_line="$macro_vhost_line $alias"
fi
else
@ -135,12 +133,12 @@ if [[ "$macro_name" == *"VHost"* ]]; then
fi
fi
# check for varnish config
if [[ "$macro_name" == *"Varnish"* ]]; then
varnish_host=$vhost
if [[ "$macro_name" == *"Subdomain"* ]]; then
if [[ "$macro" == *"Varnish"* ]]; then
varnish_host=$domain
if [[ "$macro" == *"Subdomain"* ]]; then
varnish_host="$subdomain.$varnish_host"
fi
if [ ! -f "/etc/varnish/sites.d/$varnish_host.vcl" ]; then
if [[ ! -f "/etc/varnish/sites.d/$varnish_host.vcl" ]]; then
echo "$varnish_config_file Varnish config file does not exist"
exit 1
fi
@ -148,12 +146,12 @@ if [[ "$macro_name" == *"VHost"* ]]; then
fi
# check for and set redirect
if [[ "$macro_name" == *"Redirect"* ]]; then
if [ -n "$3" ]; then
redirect=$3
if [[ "$macro" == *"Redirect"* ]]; then
if [[ -n $option ]]; then
redirect=$option
# make sure Redirect domain isn't already installed as it's own vhost
if [ -d "/srv/www/$vhost" ]; then
echo "$vhost is already installed as it's own vhost"
if [[ -d "/srv/www/$domain" ]]; then
echo "$domain is already installed as it's own vhost"
exit 1
else
macro_vhost_line="$macro_vhost_line $redirect"
@ -165,23 +163,27 @@ if [[ "$macro_name" == *"Redirect"* ]]; then
fi
# if https check for le cert
if [[ "$macro_name" == *"HTTPS"* ]]; then
cert_host=$vhost
if [[ "$macro_name" == *"Subdomain"* ]]; then
if [[ "$macro" == *"HTTPS"* ]]; then
if [[ "$macro" == *"Alias"* ]]; then
cert_host="$alias"
else
cert_host=$domain
if [[ "$macro" == *"Subdomain"* ]]; then
cert_host="$subdomain.$cert_host"
fi
if [ ! -f "/etc/ssl/letsencrypt/$cert_host.pem" ]; then
fi
if [[ ! -f "/etc/ssl/letsencrypt/$cert_host.pem" ]]; then
echo "cert file for $cert_host does not exist"
exit 1
fi
fi
# create / edit apache conf
echo "$macro_vhost_line" > /etc/apache2/sites-available/$vhost_conf
echo "$macro_vhost_line" > /etc/apache2/sites-available/$domain_conf
# enable apache conf
if [[ ! -h /etc/apache2/sites-enabled/$vhost_conf ]]; then
a2ensite --quiet $vhost_conf
if [[ ! -h /etc/apache2/sites-enabled/$domain_conf ]]; then
a2ensite --quiet $domain_conf
fi
# restart apache

View File

@ -12,45 +12,24 @@ help()
thisfilename=$(basename -- "$0")
echo "Make sure all home (/home/...) and virtualhost (/srv/www/...) files are owned by correct users."
echo ""
echo "usage: $thisfilename [OPTIONS]"
echo "usage: $thisfilename [-n|-v] [-h]"
echo ""
echo " -h Print this help."
echo " -n dry-run - List all files that need modification, but don't actually do anything."
echo " -v verbose - List all files that are being modified."
exit
}
while getopts "hvn" opt; do
case "${opt}" in
h )
help
;;
v )
mode=verbose
;;
n )
mode=dry-run
;;
\? )
echo "Invalid option: $OPTARG"
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument"
exit 1
;;
esac
done
vhost:getoptions "$@"
for VHOST in /srv/www/*/; {
# get username
USER=$(stat -c '%U' $VHOST)
# make sure all files & dirs are owned by user
if [ "$mode" = "verbose" ] || [ "$mode" = "dry-run" ]; then
if [[ -n $verbose ]] || [[ -n $dryrun ]]; then
/usr/bin/find $VHOST ! -user $USER
fi
if [ "$mode" != "dry-run" ]; then
if [[ -n $dryrun ]]; then
/usr/bin/find $VHOST ! -user $USER -exec chown $USER {} +
fi
@ -61,10 +40,10 @@ for HOME in /home/*/; {
# get username
USER=$(stat -c '%U' $HOME)
# make sure all files & dirs are owned by user
if [ "$mode" = "verbose" ] || [ "$mode" = "dry-run" ]; then
if [[ -n $verbose ]] || [[ -n $dryrun ]]; then
/usr/bin/find $HOME ! -user $USER
fi
if [ "$mode" != "dry-run" ]; then
if [[ -n $dryrun ]]; then
/usr/bin/find $HOME ! -user $USER -exec chown $USER {} +
fi

View File

@ -12,12 +12,13 @@ help()
thisfilename=$(basename -- "$0")
echo "Creates default MySQL database and db user for specified virtualhost."
echo ""
echo "usage: $thisfilename virtualhost [OPTIONS]"
echo "usage: $thisfilename -d <domain> [OPTIONS]"
echo ""
echo " -h Print this help."
echo " -u USERNAME Username for accessing the database. Optional, autogenerated if none specified."
echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
echo " -s Save db info to /home/username/.my.cnf. Warning! This inlcudes the unencrypted password."
echo " -d <domain> Domain name of VirtualHost to remove."
echo " -u <username> Username for accessing the database. Optional, autogenerated if none specified."
echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -w Write db info to /home/username/.my.cnf. Warning! This inlcudes the unencrypted password."
echo " -v Verbose - output newly created db info to console."
echo ""
echo " MySQL database names is based on virtualhost with . replaced by the word 'dot'"
@ -26,54 +27,19 @@ help()
echo " e.g. for virtualost example.com the db name will be 'exampledotcom' and the"
echo " username will be examplec@example.com."
echo " It is highly recommended to use either the -s or -v option if you don't use -p."
exit
}
while getopts "hu:p:sv" opt; do
case "${opt}" in
h )
help
exit;;
u )
username=${OPTARG}
;;
p )
password=${OPTARG}
;;
s )
save=true
;;
v )
verbose=true
;;
\? )
echo "Invalid option: $OPTARG"
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument"
exit 1
;;
esac
done
vhost:getoptions "$@"
shift $((OPTIND-1))
# check for and set virtualhost
if [ -n "$1" ]; then
virtualhost="${1,,}"
else
echo "virtualhost not set"
exit 1
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
echo "virtualhost=$virtualhost username=$username password=$password save=$save verbose=$verbose"
exit
# make sure virtualhost exists
if [ ! -d /srv/www/$virtualhost ]; then
echo "virtualhost $virtualhost does not exist"
if [[ ! -d /srv/www/$domain ]]; then
echo "virtualhost $domain does not exist"
exit 1
fi
@ -82,25 +48,21 @@ database=${virtualhost//./dot}
database=${database//-/dash}
# make sure database doesn't already exist
if [ -d /var/lib/mysql/$database ]; then
if [[ -d /var/lib/mysql/$database ]]; then
echo "database $database already exists"
exit 1
fi
# get & set username of virtualhost
vhost_username=$(stat -c '%U' /srv/www/$virtualhost)
vhost_username=$(stat -c '%U' /srv/www/$domain)
# check for and set mysql username
if [ -n "$2" ]; then
username=$2
else
username=$vhost_username@$virtualhost
if [[ -z $username ]]; then
username=$vhost_username@$domain
fi
# check for and set mysql password
if [ -n "$3" ]; then
password=$3
else
if [[ -z $password ]]; then
password=`/usr/bin/pwgen 16 1`
fi
@ -110,7 +72,7 @@ mysql -e "GRANT ALL PRIVILEGES ON $database.* TO '$username'@'localhost';"
mysqladmin flush-privileges
# save mysql db info to file
if [ -n $save ]; then
if [[ -n $write ]]; then
touch /home/$vhost_username/.my.cnf
chown $vhost_username:$vhost_username /home/$vhost_username/.my.cnf
chmod 640 /home/$vhost_username/.my.cnf
@ -121,6 +83,6 @@ if [ -n $save ]; then
echo "password=$password" >> /home/$vhost_username/.my.cnf
fi
if [ -n $verbose ]; then
if [[ -n $verbose ]]; then
echo "database=$database user=$username password=$password"
fi

View File

@ -12,22 +12,19 @@ help()
thisfilename=$(basename -- "$0")
echo "Remove MySQL database and default db user for the specified virtualhost."
echo ""
echo "usage: $thisfilename virtualhost."
echo "usage: $thisfilename -d <domain>"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to MySQL db for."
exit
}
# check for and set virtualhost.
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
virtualhost="${1,,}"
fi
else
echo "virtualhost not set"
exit 1
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
# set database name
@ -38,9 +35,9 @@ database=${database//-/dash}
mysql -e "DROP DATABASE IF EXISTS $database;"
# set default username and attempt to drop user
if [ -d /srv/www/$virtualhost ]; then
vhost_username=$(stat -c '%U' /srv/www/$virtualhost)
username=$vhost_username@$virtualhost
if [ -d /srv/www/$domain ]; then
vhost_username=$(stat -c '%U' /srv/www/$domain)
username=$vhost_username@$domain
mysql -e "DROP USER IF EXISTS '$username'@'localhost';"
mysqladmin flush-privileges
fi

View File

@ -12,67 +12,39 @@ help()
thisfilename=$(basename -- "$0")
echo "Add system user to server."
echo ""
echo "usage: $thisfilename username [OPTIONS]"
echo "usage: $thisfilename -u <domain> [-p <password> [-i <uid>] [-w] [-h]"
echo ""
echo " -h Print this help."
echo " -p PASSWORD Password for username. Optional, random password generated if none specified."
echo " -u UID Numberic User ID to assign to user. Optional, next available uid set if none specified."
echo " -s Save user info to /home/username/.passwd. Warning! This inlcudes the unencrypted password."
echo " -u <domain> System username to add to server."
echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -i <uid> Numberic User ID to assign to user. Optional, next available uid set if none specified."
echo " -w Write user info to /home/username/.passwd. Warning! This inlcudes the unencrypted password."
exit
}
# check for and set username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
username="${1,,}"
fi
else
vhost:getoptions "$@"
# check for username
if [ -z "$username" ]; then
echo "username not set"
exit 1
fi
while getopts "hp:su:" opt; do
case "${opt}" in
h )
help
;;
p )
password=${OPTARG}
;;
s )
save=true
;;
u )
uid=${OPTARG}
;;
\? )
echo "Invalid option: $OPTARG"
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument"
exit 1
;;
esac
done
# generate password if none specified
if [ ! -n "$password" ]; then
if [ -z "$password" ]; then
password=`/usr/bin/pwgen 12 1`
fi
# get next UID if none specified
if [ ! -n "$uid" ]; then
userid=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=65534; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
if [ -z "$uid" ]; then
uid=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=65534; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
fi
# user & related files are only added if they don't already exist
# in this way it's safe to repeatedly try to add the same user
if ! /bin/grep -q "^$username:" /etc/passwd; then
newusers="$username:$password:$userid:$userid::/home/$username:/bin/bash"
newusers="$username:$password:$uid:$uid::/home/$username:/bin/bash"
echo "$newusers"|newusers
pwck -s
grpck -s
@ -105,7 +77,7 @@ if [[ ! -f "/home/$username/.profile" ]]; then
install -o $username -g $username -m 640 /etc/skel/.profile /home/$username
fi
if [ -n "$save" ]; then
if [[ -n $write ]]; then
if [[ ! -f "/home/$username/.passwd" ]]; then
touch /home/$username/.passwd
chmod 640 /home/$username/.passwd

View File

@ -12,20 +12,17 @@ help()
thisfilename=$(basename -- "$0")
echo "Remove user from this server."
echo ""
echo "usage: $thisfilename username"
echo "usage: $thisfilename -u <username> [-h]"
echo ""
echo " -h Print this help."
echo " -u <username> System username to remove from server."
exit
}
# check for and set username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
username="${1,,}"
fi
else
vhost:getoptions "$@"
# check for username
if [ -z "$username" ]; then
echo "username not set"
exit 1
fi

View File

@ -4,6 +4,8 @@
# https://git.stack-source.com/msb/vhost-stack
# MIT License Copyright (c) 2021 Matthew Saunders Brown
# CURRENTLY IN DEBUG MODE. ECHOS COMMANDS, DOES NOT RUN ANYTHING
# load include file
source $(dirname $0)/vhost.sh
@ -12,20 +14,17 @@ help()
thisfilename=$(basename -- "$0")
echo "Rebuild jail for specified user."
echo ""
echo "usage: $thisfilename username [OPTIONS]"
echo "usage: $thisfilename -u <username> [-h]"
echo ""
echo " -h Print this help."
echo " -u <username> System username to reset jail for."
exit
}
# check for and set username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
username="${1,,}"
fi
else
vhost:getoptions "$@"
# check for username
if [ -z "$username" ]; then
echo "username not set"
exit 1
fi

View File

@ -12,20 +12,18 @@ help()
thisfilename=$(basename -- "$0")
echo "Jail specified user."
echo ""
echo "usage: $thisfilename username"
echo "usage: $thisfilename -u <username> [-h]"
echo ""
echo " -h Print this help."
echo " -u <username> System username to jail."
exit
}
# check for and set username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
username="${1,,}"
fi
else
vhost:getoptions "$@"
# check for username
if [ -z "$username" ]; then
echo "username not set"
exit 1
fi
@ -40,7 +38,7 @@ if [[ ! -d /home/$username ]]; then
exit 1
fi
if [[ -d "/usr/jails/$username" ]]; then
if [[ -d /usr/jails/$username ]]; then
echo "/usr/jails/$username already exists"
exit 1
fi

View File

@ -10,9 +10,9 @@ source $(dirname $0)/vhost.sh
help()
{
thisfilename=$(basename -- "$0")
echo "Add file to all existing jails."
echo "Add file or directory to all existing jails."
echo ""
echo "usage: $thisfilename pathtofile"
echo "usage: $thisfilename <path_to_file_or_directory>"
echo ""
echo " -h Print this help."
exit
@ -26,13 +26,13 @@ if [ -n "$1" ]; then
cpfile=$1
fi
else
echo "file to copy in to jails not set"
echo "file or directory to copy in to jails not set"
exit 1
fi
# make sure file exists
if [ ! -f "$cpfile" ]; then
echo "invalid file for copying in to jails"
if [[ ! -f $cpfile ]] && [[ ! -d $cpfile ]]; then
echo "invalid file or directory for copying in to jails"
exit 1
fi

View File

@ -24,13 +24,7 @@ help()
exit
}
# check for -h
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
exit
fi
fi
vhost:getoptions "$@"
# make sure jails dir exists
if [[ ! -e /usr/jails/ ]]; then

View File

@ -10,34 +10,31 @@ source $(dirname $0)/vhost.sh
help()
{
thisfilename=$(basename -- "$0")
echo "Disables Varnish config for specified virtualhost."
echo "Disables Varnish config for specified domain (VirtualHost)."
echo ""
echo "usage: $thisfilename virtualhost"
echo "usage: $thisfilename -d <domain> [-h]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name (VirtualHost) to disable Varnish for."
echo ""
echo " Varnish is proxied through Apache. This disables the"
echo " Apache proxy to Varnish and removes the varnish config."
exit
}
# check for and set virtualhost
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
virtualhost="${1,,}"
fi
else
echo "virtualhost not set"
exit 1
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
# grab macro line from virtualhost config
if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$virtualhost.conf` ; then
if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$domain.conf` ; then
macro_name=`echo "$macro_vhost_line" | awk '{print $2}'`
else
echo "$virtualhost is not configured with mod_macro"
echo "$domain is not configured with mod_macro"
exit 1
fi
@ -45,9 +42,9 @@ fi
if [[ $macro_name =~ ^.*Varnish$ ]]; then
# set new macro_name
macro_name=`echo $macro_name | sed -e 's|Varnish$||'`
vhost_enable="$macro_name $virtualhost"
vhost_enable="$macro_name $domain"
else
echo "Varnish is not enabled for $virtualhost"
echo "Varnish is not enabled for $domain"
exit 1
fi
@ -59,8 +56,8 @@ fi
/usr/local/bin/vhost-enable.sh $vhost_enable
if [ -f /etc/varnish/sites.d/$virtualhost ]; then
rm /etc/varnish/sites.d/$virtualhost
if [[ -f /etc/varnish/sites.d/$domain ]]; then
rm /etc/varnish/sites.d/$domain
/usr/local/bin/vhost-varnish-update-sites.sh $vhost_enable
# uncomment to flush varnish cache
# systemctl is-active --quiet varnish && systemctl reload --quiet varnish

View File

@ -12,60 +12,57 @@ help()
thisfilename=$(basename -- "$0")
echo "Enables Varnish for specified virtualhost."
echo ""
echo "usage: $thisfilename virtualhost. [OPTIONS]"
echo "usage: $thisfilename -d <domain> [-h]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name (VirtualHost) to enable Varnish for."
echo ""
echo " Creates Varnish config, loads it in Varnish and then"
echo " enables Apache proxy to Varnish for virtualhost."
exit
}
# check for and set virtualhost
# check for and set username
if [ -n "$1" ]; then
if [ $1 == "-h" ]; then
help
else
virtualhost="${1,,}"
fi
else
echo "virtualhost not set"
exit 1
vhost:getoptions "$@"
# check for domain (virtualhost)
if [[ -z $domain ]]; then
echo "domain is required"
exit
fi
# make sure virtualhost is enabled via symlink
if [ ! -h "/etc/apache2/sites-enabled/$virtualhost.conf" ]; then
if [[ ! -h "/etc/apache2/sites-enabled/$domain.conf" ]]; then
echo "virtualhost is not enabled"
exit 1
fi
# make sure virtualhost config is in standard location
if [ ! -f "/etc/apache2/sites-available/$virtualhost.conf" ]; then
echo "virtualhost config for $virtualhost not in /etc/apache2/sites-available/"
if [[ ! -f "/etc/apache2/sites-available/$domain.conf" ]]; then
echo "virtualhost config for $domain not in /etc/apache2/sites-available/"
exit 1
fi
# grab macro line from virtualhost config
if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$virtualhost.conf` ; then
if macro_vhost_line=`grep -m 1 "Use .*" /etc/apache2/sites-available/$domain.conf` ; then
macro_name=`echo "$macro_vhost_line" | awk '{print $2}'`
else
echo "$virtualhost is not configured with mod_macro"
echo "$domain is not configured with mod_macro"
exit 1
fi
# make sure Varnish is not already enabled
if [[ $macro_name =~ ^.*Varnish$ ]]; then
echo "Varnish already enabled for $virtualhost"
echo "Varnish already enabled for $domain"
exit 1
fi
# check for valid HTTPS VHost macro
if [[ $macro_name =~ ^VHost[[:alpha:]]*HTTPS$ ]]; then
macro_name_new="${macro_name}Varnish"
vhost_enable="$macro_name_new $virtualhost"
vhost_enable="$macro_name_new $domain"
else
echo "$virtualhost must be enabled with an HTTPS VHost macro"
echo "$domain must be enabled with an HTTPS VHost macro"
exit 1
fi
@ -83,27 +80,27 @@ if [[ "$macro_name" == *"Alias"* ]]; then
fi
# check for ssl cert
if [ ! -f "/etc/ssl/letsencrypt/$virtualhost.pem" ]; then
echo "$virtualhost.pem cert file does not exist"
if [[ ! -f "/etc/ssl/letsencrypt/$domain.pem" ]]; then
echo "$domain.pem cert file does not exist"
exit 1
fi
# make sure varnish is installed
if [ ! -f /etc/varnish/sites.d/example.com.vcl ]; then
if [[ ! -f /etc/varnish/sites.d/example.com.vcl ]]; then
echo "Varnish not installed & configured on this server"
exit 1
fi
# check for / create varnish config
if [ ! -f "/etc/varnish/sites.d/$virtualhost.vcl" ]; then
if [[ ! -f "/etc/varnish/sites.d/$domain.vcl" ]]; then
# create varnish config
echo "sub vcl_recv {" > /etc/varnish/sites.d/$virtualhost.vcl
echo " if (req.http.host == \"$virtualhost\" || req.http.host == \"www.$virtualhost\") {" >> /etc/varnish/sites.d/$virtualhost.vcl
echo " # Uncomment next line to bypass varnish cache" >> /etc/varnish/sites.d/$virtualhost.vcl
echo " #return (pass);" >> /etc/varnish/sites.d/$virtualhost.vcl
echo " call wordpress;" >> /etc/varnish/sites.d/$virtualhost.vcl
echo " }" >> /etc/varnish/sites.d/$virtualhost.vcl
echo "}" >> /etc/varnish/sites.d/$virtualhost.vcl
echo "sub vcl_recv {" > /etc/varnish/sites.d/$domain.vcl
echo " if (req.http.host == \"$domain\" || req.http.host == \"www.$domain\") {" >> /etc/varnish/sites.d/$domain.vcl
echo " # Uncomment next line to bypass varnish cache" >> /etc/varnish/sites.d/$domain.vcl
echo " #return (pass);" >> /etc/varnish/sites.d/$domain.vcl
echo " call wordpress;" >> /etc/varnish/sites.d/$domain.vcl
echo " }" >> /etc/varnish/sites.d/$domain.vcl
echo "}" >> /etc/varnish/sites.d/$domain.vcl
/usr/local/bin/vhost-varnish-update-sites.sh
systemctl is-active --quiet varnish && systemctl reload --quiet varnish
fi

View File

@ -12,7 +12,7 @@ help()
thisfilename=$(basename -- "$0")
echo "Makes sure all existing varnish configs are loaded."
echo ""
echo "usage: $thisfilename"
echo "usage: $thisfilename [-h]"
echo ""
echo " -h Print this help."
echo ""

View File

@ -37,6 +37,59 @@ function vhost::validate_domain () {
fi
}
function vhost:getoptions () {
local OPTIND
while getopts "d:i:o:p:u:jhnvw" opt ; do
case "${opt}" in
h ) # display help and exit
help
exit
;;
d ) # domain name (virtualhost) to act on
domain=${OPTARG,,}
if ! vhost::validate_domain $domain; then
echo "ERROR: $domain is not a valid domain name."
exit
fi
;;
i ) # User ID (UID) for new user
uid=${OPTARG}
;;
i ) # option - usually applied to previously specified variable
# e.g. could be subdomain or alias depending on the macro defined
option=${OPTARG}
;;
p ) # password
password=${OPTARG}
;;
u ) # username
username=${OPTARG,,}
;;
j ) # jail - if enabled user will be jailed
jail=true
;;
n ) # dry-run
dryrun=true
;;
v ) # verbose
verbose=true
;;
w ) # write - store data in file
write=true
;;
\? )
echo "Invalid option: $OPTARG"
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument"
exit 1
;;
esac
done
shift $((OPTIND-1))
}
# check for local config, which can be used to override any of the above
if [[ -f /usr/local/etc/vhost.conf ]]; then
source /usr/local/etc/vhost.conf

View File

@ -201,10 +201,10 @@
<Macro VHostAliasHTTP $vhost $username $alias>
<VirtualHost *:80>
ServerName $vhost
ServerAlias www.$vhost
ServerAlias $vhost.example.com
DocumentRoot /srv/www/$alias/html
ServerName $alias
ServerAlias www.$alias
ServerAlias $alias.example.com
DocumentRoot /srv/www/$vhost/html
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.4-fpm-$username.sock|fcgi://localhost"
</FilesMatch>
@ -213,10 +213,10 @@
<Macro VHostAliasHTTPS $vhost $username $alias>
<VirtualHost *:80>
ServerName $vhost
ServerAlias www.$vhost
ServerAlias $vhost.example.com
DocumentRoot /srv/www/$alias/html
ServerName $alias
ServerAlias www.$alias
ServerAlias $alias.example.com
DocumentRoot /srv/www/$vhost/html
## <Location "/">
## <If "%{REQUEST_URI} !~ m#^/.well-known/acme-challenge/#">
## Redirect 301 "https://%{HTTP_HOST}%{REQUEST_URI}"
@ -227,14 +227,14 @@
</FilesMatch>
</VirtualHost>
<VirtualHost *:443>
ServerName $vhost
ServerAlias www.$vhost
ServerAlias $vhost.example.com
DocumentRoot /srv/www/$alias/html
ServerName $alias
ServerAlias www.$alias
ServerAlias $alias.example.com
DocumentRoot /srv/www/$vhost/html
<FilesMatch ".+\.ph(ar|p|tml)$">
SetHandler "proxy:unix:/run/php/php7.4-fpm-$username.sock|fcgi://localhost"
</FilesMatch>
SSLEngine on
SSLCertificateFile /etc/ssl/letsencrypt/$vhost.pem
SSLCertificateFile /etc/ssl/letsencrypt/$alias.pem
</VirtualHost>
</Macro>