Apache – How to configure SSL in apache

apache-httpdconfigurationrhelssl

I have installed apache in RHEL 6. Everything is working fine. What all changes and configurations should be done to use
https://localhost:443/.

If I change the "Listen 80" to 443 it is throwing an SSL connection error

"Error 107 (net::ERR_SSL_PROTOCOL_ERROR): SSL protocol error."

Best Answer

If you are using apache2, then you have to do the following:

Step 1: Use OpenSSL to produce the keys that are used to secure your site. These keys are used when encrypting and decrypting the traffic to your secure site.

$ openssl genrsa -out mydomain.key 1024

This command will create a 1024 bit private key and puts it in the file mydomain.key.

Step 2: Generate your own certificate.

$ openssl req -new -key mydomain.key -x509 -out mydomain.crt

Step 3: Keep the private key in the directory /etc/apache2/ssl.key/ and certificate in the directory /etc/apache2/ssl.crt/.

Note: The ssl.key directory must be only readable by root.

Step 4: Now you need to edit httpd.conf file in /etc/apache2.

Now this file should include content like this:

NameVirtualHost *:80
NameVirtualHost *:443
Listen 443

<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain
ServerName www.mydomain.com
ServerAlias mydomain.com
</VirtualHost>


<VirtualHost *:443>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain-secure
ServerName mail.mydomain.com
SSLEngine on
SSLCertificateFile /etc/apache2/ssl.crt/mydomain.crt
SSLCertificateKeyFile /etc/apache2/ssl.key/mydomain.key
</VirtualHost>


<Directory /srv/www/htdocs/mydomain-secure>
SSLRequireSSL
</Directory>


<VirtualHost *:80>
ServerAdmin webmaster@mydomain.com
DocumentRoot /srv/www/htdocs/mydomain
ServerName mail.mydomain.com
RedirectMatch permanent (/.*) https://mail.mydomain.com$1
</VirtualHost>
Related Question