Search blog

Friday, March 20, 2015

Enable SSL in Unbuntu 14.04 in Localhost/VirtualHost

Follow the steps below to enable SSL in your Localhost and VirtualHost:

1. IF NOT USING VirtualHost:

Open the file 'default-ssl.conf' and you might see something like below. You will have to make changes to the lines in BOLD.
 <IfModule mod_ssl.c>  
   <VirtualHost _default_:443>  
     ServerAdmin webmaster@localhost  
     DocumentRoot /var/www/html    
     
     ErrorLog ${APACHE_LOG_DIR}/error.log  
     CustomLog ${APACHE_LOG_DIR}/access.log combined  
     SSLEngine on  
     SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem  
     SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key  
     <FilesMatch "\.(cgi|shtml|phtml|php)$">  
             SSLOptions +StdEnvVars  
     </FilesMatch>  
     <Directory /usr/lib/cgi-bin>  
             SSLOptions +StdEnvVars  
     </Directory>  
     BrowserMatch "MSIE [2-6]" \  
             nokeepalive ssl-unclean-shutdown \  
             downgrade-1.0 force-response-1.0  
     BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown  
   </VirtualHost>  
 </IfModule>  
Also you will have to add the following line just below the line 'DcoumentRoot /var/www/html':
 <Directory /var/www/html>  
   Options All  
   AllowOverride All  
   Require all granted   
 </Directory>  
Enable SSL:
 sudo a2ensite default-ssl.conf  
Then finally restart Apache and you should be done:
 sudo service apache2 restart  
2. IF USING VirtualHost:

Make a COPY of the file 'default-ssl.conf' and rename the copied file as 'your-site-name.ssl.conf' and make the following changes:
 <IfModule mod_ssl.c>  
   <VirtualHost _default_:443>  
     ServerAdmin webmaster@localhost 
     ServerName your-site.local
     ServerAlias www.you-site.local 
     DocumentRoot /var/www/html/path-to-your-site    
     
     ErrorLog ${APACHE_LOG_DIR}/error.log  
     CustomLog ${APACHE_LOG_DIR}/access.log combined  
     SSLEngine on  
     SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem  
     SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key  
     <FilesMatch "\.(cgi|shtml|phtml|php)$">  
             SSLOptions +StdEnvVars  
     </FilesMatch>  
     <Directory /usr/lib/cgi-bin>  
             SSLOptions +StdEnvVars  
     </Directory>  
     BrowserMatch "MSIE [2-6]" \  
             nokeepalive ssl-unclean-shutdown \  
             downgrade-1.0 force-response-1.0  
     BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown  
   </VirtualHost>  
 </IfModule>  
Once again add the following lines just below the line 'DcoumentRoot /var/www/html':
 <Directory /var/www/html>  
   Options All  
   AllowOverride All  
   Require all granted   
 </Directory>  
Enable SSL:
 sudo a2ensite your-sitename.local-ssl.conf  
Then finally restart Apache and you should be done:
 sudo service apache2 restart  

No comments:

Post a Comment

Thank you for your Feedback!
www.evagabond.me

Top 5 Posts (Weekly)