sufehmi icon

bulk-create-apache2-SSL-vhosts.sh ; revision: 20191027

sufehmi | PRO | 10/27/19 01:06:53 PM UTC | 0 ⭐ | 786 👁️ | Never ⏰ | []
Bash |

1.98 KB

|

None

|

0 👍

/

0 👎

#!/bin/bash
 
### 1 ### This script enables you to create thousands of SSL vhost files very quickly & easily
###       Just put the subdomain names into a file called vhost-list.txt
 
### 2 ### This is the script that you will need to run if you enable SSL here : by https://pastebin.com/gkTeHPDN 
 
### 3 #### This script need file /etc/letsencrypt/options-ssl-apache.conf to work 
###        Copy-paste this pastebin to that file : https://pastebin.com/3qrGfSft
 
vhost_location='/etc/apache2/sites-available/'
 
vhost_template="<VirtualHost *:443>\n
        ServerAdmin     [email protected]\n
        ServerName      VHOST\n
\n
        DocumentRoot /var/www/VHOST\n
\n
        <Directory /var/www/VHOST/>\n
                Options -Indexes +FollowSymLinks +MultiViews\n
                AllowOverride All\n
                Order allow,deny\n
                allow from all\n
        </Directory>\n
\n
        ErrorLog \${APACHE_LOG_DIR}/error-VHOST.log\n
        LogLevel error\n
\n
        CustomLog \${APACHE_LOG_DIR}/access-VHOST.log combined\n
 
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/VHOST/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/VHOST/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/VHOST/chain.pem
 
</VirtualHost>"
 
########### START ################################
vhost=( `cat "vhost-list.txt" `)
 
for t in "${vhost[@]}"
do
        echo $t
 
        # write VHOST.conf
        echo -e $vhost_template > $vhost_location/$t-ssl.conf
 
        # find & replace all VHOST
        /bin/sed -i -e "s/VHOST/$t/g" $vhost_location/$t-ssl.conf
 
        # enable this vhost
        /usr/sbin/a2ensite $t-ssl
 
        ### if you need SSL certificate for this vhost,
        ### you can use Let's Encrypt
        ### NOTE: this vhost's DNS must be already resolvable
        #certbot  --apache --redirect -n -d  $t
 
 
done
 
# restart apache to activate the new vhosts
/etc/init.d/apache2 restart
 
# done !

Comments