Daca data trecuta am prezentat un script care [adauga automat vhost-uri][1], de data asta va prezint scriptul care adauga automat vhosturi si genereaza certificat SSL self signed. Aceast script este util in cazul in care serverul tau nu are panou de control gen cPanel, DirectAdmin, Plesk, etc. Scriptul se executa in acelasi fel ca cel care adauga doar vhost-uri, adica prin executarea comenzii: . vhost-ssl.sh domeniu.tld sau . vhost-ssl.sh subdomeniu.domeniu.tld

#!/bin/bash  
#  
\# This script is released under CC BY-SA copyright terms.  
#

vhost=$1  
if [[ -z “$vhost” ]]; then  
echo “Usage bash vhost.sh domain.tld or sub.domain.tld”  
exit 1;  
else  
echo “Your domain is $vhost”  
fi

echo “Please enter the IP address on which the SSL cert will be installed”  
echo “if none entered, the script will configure the vhost with the default”  
echo “IP address on which the apache webserver is running!”  
read -p “Enter IP address or hit Enter to contiune > ” IP

if [[ $IP < 1 ]] ; then  
host=”*”  
else  
host=$IP  
fi

mkdir /var/www/$vhost  
mkdir /var/www/$vhost/htdocs  
mkdir /var/www/$vhost/cgi-bin  
mkdir /var/www/$vhost/logs  
mkdir /var/www/$vhost/ssl-cert  
a2enmod ssl  
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /var/www/$vhost/ssl-cert/$vhost.key -out /var/www/$vhost/ssl-cert/$vhost.crt

if [ ! -f /etc/apache2/conf.d/virtual.conf ]; then  
mkdir /var/www/default  
touch /etc/apache2/conf.d/virtual.conf  
echo “#” > /etc/apache2/conf.d/virtual.conf  
echo “# We’re running multiple virtual hosts.” >> /etc/apache2/conf.d/virtual.conf  
echo “#” >> /etc/apache2/conf.d/virtual.conf  
echo “<VirtualHost *:80>” >> /etc/apache2/conf.d/virtual.conf  
echo -e “\tServerAdmin root@localhost” >> /etc/apache2/conf.d/virtual.conf  
echo -e “\tDocumentRoot /var/www/default” >> /etc/apache2/conf.d/virtual.conf  
echo “</VirtualHost>” >> /etc/apache2/conf.d/virtual.conf  
fi

echo “#” >> /etc/apache2/sites-available/$vhost  
echo “# $vhost (/etc/apache2/sites-available/$vhost)” >> /etc/apache2/sites-available/$vhost  
echo “#” >> /etc/apache2/sites-available/$vhost  
echo “” >> /etc/apache2/sites-available/$vhost  
echo “<VirtualHost $host:443>” >> /etc/apache2/sites-available/$vhost  
echo -e “\tServerAdmin admin@$vhost” >> /etc/apache2/sites-available/$vhost  
echo -e “\tServerName $vhost:443″ >> /etc/apache2/sites-available/$vhost  
echo -e “\tServerAlias www.$vhost:443″ >> /etc/apache2/sites-available/$vhost  
echo “” >> /etc/apache2/sites-available/$vhost  
echo -e “\t# Indexes + Directory Root.” >> /etc/apache2/sites-available/$vhost  
echo -e “\tDirectoryIndex index.php index.html” >> /etc/apache2/sites-available/$vhost  
echo -e “\tDocumentRoot /var/www/$vhost/htdocs/” >> /etc/apache2/sites-available/$vhost  
echo “” >> /etc/apache2/sites-available/$vhost  
echo -e “\t# CGI Directory” >> /etc/apache2/sites-available/$vhost  
echo -e “\tScriptAlias /cgi-bin/ /var/www/$vhost/cgi-bin/” >> /etc/apache2/sites-available/$vhost  
echo -e “\t<Location /cgi-bin>” >> /etc/apache2/sites-available/$vhost  
echo -e “\t\tOptions +ExecCGI” >> /etc/apache2/sites-available/$vhost  
echo -e “\t</Location>” >> /etc/apache2/sites-available/$vhost  
echo “” >> /etc/apache2/sites-available/$vhost  
echo -e “\t# Logfiles” >> /etc/apache2/sites-available/$vhost  
echo -e “\tErrorLog /var/www/$vhost/logs/error.log” >> /etc/apache2/sites-available/$vhost  
echo -e “\tCustomLog /var/www/$vhost/logs/access.log combined” >> /etc/apache2/sites-available/$vhost  
echo “” >> /etc/apache2/sites-available/$vhost  
echo -e “\t<FilesMatch \”\.(cgi|shtml|phtml|php)$\”>” >> /etc/apache2/sites-available/$vhost  
echo -e “\t\tSSLOptions +StdEnvVars” >> /etc/apache2/sites-available/$vhost  
echo -e “\t</FilesMatch>” >> /etc/apache2/sites-available/$vhost  
echo -e “\t<Directory /usr/lib/cgi-bin>” >> /etc/apache2/sites-available/$vhost  
echo -e “\t\tSSLOptions +StdEnvVars” >> /etc/apache2/sites-available/$vhost  
echo -e “\t</Directory>” >> /etc/apache2/sites-available/$vhost  
echo -e “\tBrowserMatch \”MSIE [2-6]\” \\” >> /etc/apache2/sites-available/$vhost  
echo -e “\t\tnokeepalive ssl-unclean-shutdown \\” >> /etc/apache2/sites-available/$vhost  
echo -e “\t\tdowngrade-1.0 force-response-1.0″ >> /etc/apache2/sites-available/$vhost  
echo -e “\tBrowserMatch \”MSIE [17-9]\” ssl-unclean-shutdown” >> /etc/apache2/sites-available/$vhost  
echo -e “\tSSLEngine on” >> /etc/apache2/sites-available/$vhost  
echo -e “\tSSLCertificateFile /var/www/$vhost/ssl-cert/$vhost.crt” >> /etc/apache2/sites-available/$vhost  
echo -e “\tSSLCertificateKeyFile /var/www/$vhost/ssl-cert/$vhost.key” >> /etc/apache2/sites-available/$vhost  
echo “</VirtualHost>” >> /etc/apache2/sites-available/$vhost  
echo “” >> /etc/apache2/sites-available/$vhost

#generating a new index file  
echo “<html xmlns=\”http://www.w3.org/1999/xhtml\” xml:lang=\”en\” lang=\”en\”>” > /var/www/$vhost/htdocs/index.html  
echo “$vhost — Coming Soon” >> /var/www/$vhost/htdocs/index.html  
echo “<meta http-equiv=\”Content-Type\” content=\”text/html; charset=UTF-8\”/>” >> /var/www/$vhost/htdocs/index.html  
echo “<meta name=\”description\” content=\”This is a default index page for a new domain.\”/>” >> /var/www/$vhost/htdocs/index.html  
echo “<style type=\”text/css\”>” >> /var/www/$vhost/htdocs/index.html  
echo “
h1 {font-size:64px; color:#555555; margin: 70px 0 50px 0;}
” >> /var/www/$vhost/htdocs/index.html echo “</style>” >> /var/www/$vhost/htdocs/index.html echo “</head>” >> /var/www/$vhost/htdocs/index.html echo “” >> /var/www/$vhost/htdocs/index.html echo “

$vhost

” >> /var/www/$vhost/htdocs/index.html echo “” >> /var/www/$vhost/htdocs/index.html echo “</html>” >> /var/www/$vhost/htdocs/index.html a2ensite $vhost /etc/init.d/apache2 reload echo “Your website $vhost is up and running” </pre>