Getting the required software
For an SSL encrypted web server you will need a few things. Depending on your install you may or may not have OpenSSL and mod_ssl, Apache’s interface to OpenSSL.
Use yum to get them if you need them.
1
| |
Yum will either tell you they are installed or will install them for you.
Generate a self-signed certificate
Using OpenSSL we will generate a self-signed certificate. If you are using this on a production server you will need a key from Trusted Certificate Authority, but if you are just using this on a personal site or for testing purposes a self-signed certificate is fine. To create the key you will need to be root so you can either su to root or use sudo in front of the commands
1 2 3 4 5 6 7 8 9 10 11 12 | |
Then we need to update the Apache SSL configuration file
1
| |
Change the paths to match where the Key file is stored. If you’ve used the method above it will be
1
| |
Then set the correct path for the Certificate Key File a few lines below. If you’ve followed the instructions above it is:
1
| |
Quit and save the file and then restart Apache
1
| |
All being well you should now be able to connect over https to your server and see a default Centos page. As the certificate is self signed browsers will generally ask you whether you want to accept the certificate. Firefox 3 won’t let you connect at all but you can override this.
Setting up the virtual hosts
Just as you set virtual hosts for http on port 80 so you do for https on port 433. A typical virtual host for a site on port 80 looks like this
1 2 3 4 5 6 7 | |
To add a sister site on port 443 you need to add the following at the top of your file
1
| |
and then a VirtualHost record something like this:
1 2 3 4 5 6 7 8 9 10 | |
Restart Apache again using
1
| |
You should now have a site working over https. If you can’t connect you probably need to open the port on your firewall:
1
| |