Automating virtual hosts
If we create a template file for a virtual host, we can easily drop new virtual hosts using a script. First, we need a template file that is similar to the following commands:
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.example.com ServerName dummy-host.example.com DocumentRoot /var/www/dummy-host.example.com ErrorLog /var/log/httpd/dummy-host.example.com-error_log CustomLog /var/log/httpd/dummy-host.example.com-access_log UseCanonicalName Off ServerSignature On <Directory "/var/www/vhosts/dummy-host.example.com"> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> </VirtualHost>
If this file is saved as /etc/httpd/conf.d/template
, it will not be used as a configuration as it does not end in .conf
. We can use it as a template with a script similar to the following commands:
#!/bin/bash CONFDIR=/etc/httpd/conf.d WEBDIR=/var/www/ mkdir -p $WEBDIR/$1 sed s/"dummy...