This guide will explain how to set up a site over https. The tutorial uses a self signed key so will work well for a personal website or testing purposes. This is provided as is so proceed at your own risk and take backups!<\/p>\n
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.<\/p>\n
yum install mod_ssl openssl<\/p>\n
Yum will either tell you they are installed or will install them for you.<\/p>\n<\/div>\n
Using OpenSSL we will generate a self-signed certificate. If you are using this on a production server you are probably likely to want 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<\/p>\n
openssl genrsa -out ca.key 1024<\/p>\n
openssl req -new -key ca.key -out ca.csr<\/p>\n
openssl x509 -req -days 365 -in ca.csr -signkey ca.key -out ca.crt<\/p>\n
cp ca.crt /etc/pki/tls/certs
\ncp ca.key /etc/pki/tls/private/ca.key
\ncp ca.csr /etc/pki/tls/private/ca.csr<\/p>\n
WARNING: Make sure that you copy the files and do not move them if you use SELinux. Apache will complain about missing certificate files otherwise, as it cannot read them because the certificate files do not have the right SELinux context.<\/p>\n
If you have moved the files and not copied them, you can use the following command to correct the SELinux contexts on those files, as the correct context definitions for /etc/pki/* come with the bundled SELinux policy.<\/p>\n
restorecon -RvF /etc/pki<\/p>\n
Then we need to update the Apache SSL configuration file<\/p>\n
vi +/SSLCertificateFile /etc/httpd/conf.d/ssl.conf<\/p>\n
Change the paths to match where the Key file is stored. If you’ve used the method above it will be<\/p>\n
SSLCertificateFile /etc/pki/tls/certs/ca.crt<\/p>\n
Then set the correct path for the Certificate Key File a few lines below. If you’ve followed the instructions above it is:<\/p>\n
SSLCertificateKeyFile /etc/pki/tls/private/ca.key<\/p>\n
Quit and save the file and then restart Apache<\/p>\n
/etc/init.d/httpd restart<\/p>\n
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.<\/p>\n<\/div>\n
Just as you set VirtualHosts for http on port 80 so you do for https on port 443. A typical VirtualHost for a site on port 80 looks like this<\/p>\n
<VirtualHost *:80> To add a sister site on port 443 you need to add the following at the top of your file<\/p>\n NameVirtualHost *:443<\/p>\n and then a VirtualHost record something like this:<\/p>\n <VirtualHost *:443> Restart Apache again using<\/p>\n /etc/init.d/httpd restart<\/p>\n<\/div>\n
\n<Directory /var/www/vhosts/yoursite.com/httpdocs>
\nAllowOverride All
\n
\nDocumentRoot /var/www/vhosts/yoursite.com/httpdocs
\nServerName yoursite.com<\/a>
\n<\/p>\n
\nSSLEngine on
\nSSLCertificateFile /etc/pki/tls/certs/ca.crt
\nSSLCertificateKeyFile /etc/pki/tls/private/ca.key
\n<Directory /var/www/vhosts/yoursite.com/httpsdocs>
\nAllowOverride All
\n
\nDocumentRoot /var/www/vhosts/yoursite.com/httpsdocs
\nServerName yoursite.com<\/a>
\n<\/p>\n