Advertisement
sufehmi

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

Oct 3rd, 2016
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.46 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. vhost_location='/etc/apache2/sites-available/'
  4. #vhost_location='/tmp/tmp/'
  5.  
  6. vhost_docroot='/var/www/mycompany/dep/SUBDOM/controller'
  7.  
  8. vhost_template="<VirtualHost *:80>\n
  9.        ServerAdmin     engineers@mycompany.com\n
  10.        ServerName      VHOST\n
  11. \n
  12.        DocumentRoot $vhost_docroot/\n
  13. \n
  14.        <Directory $vhost_docroot>\n
  15.                Options Indexes FollowSymLinks MultiViews\n
  16.                AllowOverride All\n
  17.                Order allow,deny\n
  18.                allow from all\n
  19.        </Directory>\n
  20. \n
  21.        ErrorLog \${APACHE_LOG_DIR}/error-VHOST.log\n
  22.        LogLevel error\n
  23. \n
  24.        CustomLog \${APACHE_LOG_DIR}/access-VHOST.log combined\n
  25. \n
  26. ### if you wish to force HTTPS (highly recommended!),  \n
  27. ### uncomment the following 3 lines,  \n
  28. ### then run this script as well to generate the SSL vhosts : https://pastebin.com/yhfD1yVM \n
  29. # RewriteEngine On \n
  30. # RewriteCond %{HTTPS} off \n
  31. # RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] \n
  32. \n
  33. </VirtualHost>"
  34.  
  35. ########### START ################################
  36. vhost=( `cat "vhosts-list.txt" `)
  37.  
  38. for t in "${vhost[@]}"
  39. do
  40.     echo $t
  41.  
  42.     # write VHOST.conf
  43.     echo -e $vhost_template > $vhost_location/$t.conf
  44.  
  45.     # get the SUBDOM
  46.     subdom=`echo $t | /usr/bin/cut -d'.' -f 1`
  47.  
  48.     # find & replace all VHOST
  49.     /bin/sed -i -e "s/VHOST/$t/g" $vhost_location/$t.conf
  50.  
  51.     # find & replace all SUBDOM
  52.     /bin/sed -i -e "s/SUBDOM/$subdom/g" $vhost_location/$t.conf
  53.  
  54.     # enable this vhost
  55.     /usr/sbin/a2ensite $t
  56.  
  57. done
  58.  
  59. # restart apache to activate the new vhosts
  60. /etc/init.d/apache2 restart
  61.  
  62. # done !
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement