Configuring Apache and SSL [15 May 2009]

needs:

  • apache2 server installed

OS:

  • Debian 4.0
  • it should work also on Ubuntu >=7.04

Step 1

activate ssl support for apache:

# a2enmod ssl

Step 2

add this line in your /etc/apache2/ports.conf:

Listen 443

Step 3

add this line to your /etc/apache2/sites-available/default

NameVirtualHost *:443

Step 4

get a certificate:

  • buy one from a certification authority
  • create it by yourself

Create a SSL certificate

First, you need to run make-ssl-cert using a template and sending the output into a file:

# make-ssl-cert /usr/share/ssl-cert/ssleay.cnf server.crt

Your server.crt file will contain a pair of strings, a private RSA key and a public one (the SSL certificate). The two keys are nothing more than two strings starting and ending with

-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----


-----BEGIN CERTIFICATE-----
...
-----END CERTIFICATE-----

It's recommended to cut the file in two:

  • use server-mysite.crt for the public key
  • use something like mysite.key for the private key

Now set restricted permission to the private.key file.

Last, locate your files in a directory such as /etc/apache2/ssl/

Step 5

configure your virtual host over ssl:

<VirtualHost *:443>

        SSLEngine ON
        SSLCertificateFile /etc/apache2/ssl/server-mysite.crt
        SSLCertificateKeyFile /etc/apache2/ssl/mysite.key

        ServerAdmin     you@localhost
        
        ServerName      www.mysite.net
        DocumentRoot    /srv/www/mysite
        ...
</VirtualHost>

!Tips:

  • You can have at least one website for each SSL certificate