Set Up HTTPS In Apache

Setting up HTTPS,  is also easy. As usual, open up httpd.conf found in the conf directory of your Apache installation directory.

First, you need to enable the SSL module. Make sure to uncomment the line that loads mod_ssl.so:

LoadModule ssl_module modules/mod_ssl.so

To support HTTPS, you normally would listen to port 443. You need to register it as a port that Apache listens on. After the line that says “Listen 80” add:

Listen 443

If your server has multiple IP addresses,  you can also listen to specific address and port combinations:

Listen 10.0.0.1:443
Listen 10.0.0.2:443

You will then need to define a virtual host for your secure server:

<VirtualHost *:443>
   ServerAdmin [email protected]
   DocumentRoot /www/docs/www.example.com
   ServerName www.example.com
   ErrorLog logs/www.example.com-error_log
   CustomLog logs/www.example.com-access_log common
   SLEngine On
   SSLCertificateFile /etc/httpd/conf/ssl.crt/cert.pem
   SSLCertificateKeyFile /etc/httpd/conf/ssl.key/key.pem
</VirtualHost>

<VirtualHost *:443> means this virtual host will handle HTTPS requests on any IP.

You will need a server certificate and key. Let’s say you have them as cert.pem and key.pem. Copy these to the conf/ssl.crt and conf/ssl.key directories  of your Apache installation directory.

Save and restart Apache.

That’s it!