Tuesday, September 28, 2010

Configuring SSL on Apache2 with self signed SSL certification

Apache is one of the coolest things that has happened in FOSS, and now that about 70% of web servers run Apache, it is now a nondetachable component of the Web.

Apart from its ubiquity, Apache is very handy to simulate and test network conditions.
Like recently, I had to work with two local Secure Socket Layer (SSL) web servers, i.e, servers which can be accessed only by "https://URL". The servers using SSL protocol are different from conventional HTTP protocol for they operate on port 443 instead of port 80 (for http), and are by design more secure.

Configuring Apache2 is straight forward, and I was already running it on my system. To get it serve content on port 443 (SSL), I had to perform a few simple steps.

(Presumptions: Apache2 is already configured and running on a Debian based Linux machine)
(You should perform all these operations as root/ or perform as sudo as shown below)

1. Creating self-signed certificates for SSL

* Install ssl-cert package, if not installed already. In Debian based machines

raghu@fossphosis$ sudo apt-get install ssl-cert

* Creating a default self-signed certificate, in the default directory /etc/ssl/certs

raghu@fossphosis$ sudo make-ssl-cert generate-default-snakeoil --force-overwrite

2. Enabling the locations which can be accessed by clients on SSL

To use the default option, perform

raghu@fossphosis$ sudo a2ensite default-ssl

This lets users access content from /var/www on SSL

3. Enabling SSL module itslef for Apache2

raghu@fossphosis$ sudo a2enmod ssl

4. Finally, restart Apache2 server for the changes to take place

raghu@fossphosis$ sudo /etc/init.d/apache2 restart

5. Test it by requesting for a https URL in your browser
https://localhost/
SSL Error - Google Chrome
Do acknowledge the signature verification of the certificate to browse the content;
https:--localhost - Google Chrome
Happy Secure Socket Layer serving :)

1 comment: