sufehmi

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

Oct 27th, 2019
27
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. ### 1 ### This script enables you to create thousands of SSL vhost files very quickly & easily
  4. ###       Just put the subdomain names into a file called vhost-list.txt
  5.  
  6. ### 2 ### This is the script that you will need to run if you enable SSL here : by https://pastebin.com/gkTeHPDN
  7.  
  8. ### 3 #### This script need file /etc/letsencrypt/options-ssl-apache.conf to work
  9. ###        Copy-paste this pastebin to that file : https://pastebin.com/3qrGfSft
  10.  
  11. vhost_location='/etc/apache2/sites-available/'
  12.  
  13. vhost_template="<VirtualHost *:443>\n
  14.        ServerAdmin     MY@EMAIL.COM\n
  15.        ServerName      VHOST\n
  16. \n
  17.        DocumentRoot /var/www/VHOST\n
  18. \n
  19.        <Directory /var/www/VHOST/>\n
  20.                Options -Indexes +FollowSymLinks +MultiViews\n
  21.                AllowOverride All\n
  22.                Order allow,deny\n
  23.                allow from all\n
  24.        </Directory>\n
  25. \n
  26.        ErrorLog \${APACHE_LOG_DIR}/error-VHOST.log\n
  27.        LogLevel error\n
  28. \n
  29.        CustomLog \${APACHE_LOG_DIR}/access-VHOST.log combined\n
  30.  
  31. Include /etc/letsencrypt/options-ssl-apache.conf
  32. SSLCertificateFile /etc/letsencrypt/live/VHOST/cert.pem
  33. SSLCertificateKeyFile /etc/letsencrypt/live/VHOST/privkey.pem
  34. SSLCertificateChainFile /etc/letsencrypt/live/VHOST/chain.pem
  35.  
  36. </VirtualHost>"
  37.  
  38. ########### START ################################
  39. vhost=( `cat "vhost-list.txt" `)
  40.  
  41. for t in "${vhost[@]}"
  42. do
  43.         echo $t
  44.  
  45.         # write VHOST.conf
  46.         echo -e $vhost_template > $vhost_location/$t-ssl.conf
  47.  
  48.         # find & replace all VHOST
  49.         /bin/sed -i -e "s/VHOST/$t/g" $vhost_location/$t-ssl.conf
  50.  
  51.         # enable this vhost
  52.         /usr/sbin/a2ensite $t-ssl
  53.  
  54.         ### if you need SSL certificate for this vhost,
  55.         ### you can use Let's Encrypt
  56.         ### NOTE: this vhost's DNS must be already resolvable
  57.         #certbot  --apache --redirect -n -d  $t
  58.  
  59.  
  60. done
  61.  
  62. # restart apache to activate the new vhosts
  63. /etc/init.d/apache2 restart
  64.  
  65. # done !
RAW Paste Data