To configure mod_ssl for Apache on CentOS or RedHat, you can follow these steps:
- Install mod_ssl: First, you need to install mod_ssl if it is not already installed on your system. You can use the following command to install mod_ssl:
yum install mod_ssl
- Generate SSL certificate and key: To use HTTPS for secure connections, you need to generate an SSL certificate and key. You can use the
openssl
command to generate a self-signed certificate and key:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/pki/tls/private/example.com.key -out /etc/pki/tls/certs/example.com.crt
In this example, we are creating a self-signed certificate and key for the domain example.com
. You can replace example.com
with your own domain name. This command will create a key file at /etc/pki/tls/private/example.com.key
and a certificate file at /etc/pki/tls/certs/example.com.crt
.
- Configure mod_ssl: Next, you need to configure mod_ssl to use the SSL certificate and key. Open the Apache configuration file
/etc/httpd/conf/httpd.conf
in a text editor and add the following lines:
Listen 443 https
<VirtualHost *:443>
ServerName example.com
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/example.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/example.com.key
</VirtualHost>
In this example, we are configuring Apache to listen on port 443 for HTTPS connections, and we are specifying the SSL certificate and key for the example.com
virtual host. You can replace example.com
with your own domain name.
- Restart Apache: Finally, you need to restart Apache to apply the new configuration:
systemctl restart httpd
After restarting Apache, your website should now be accessible via HTTPS using the SSL certificate and key you generated in step 2.