Apache with SSL & http redirection to https on Centos 6.7

Apache with SSL & http redirection to https on Centos 6.7

The TLS (transport layer security) and its predecessor SSL( secure sockets layer)  are the secure protocols created in order to place normal traffic in a protected, encrypted wrapper.

These protocols allow traffic to be sent safely between remote parties with secure data transfer  where  data is being intercepted and read by someone else in the middle.


In this guide, will learn how to create a self-signed SSL certificate for Apache on an Ubuntu 14.04 server.  Which will allow you to encrypt traffic from your server to client. While this does not provide the benefit of third party validation of your server's identity, it only full fills the requirements of those simply wanting to transfer information securely to the client.

Prerequisites

1. Update the Linux system

# yum update

2. Install the packages using this command for ssl and htpps


# yum install httpd 

# yum install mod_ssl openssl


Activate the SSL Module 

3. Create a file using vi or your favourite  editor for creating SSL certificates for your server

# vi /usr/local/bin/apache_ssl

The contents of the files are given below
#!/bin/bash
mkdir /etc/httpd/ssl
cd /etc/httpd/ssl

echo -e "Enter your virtual host FQDN: \nThis will generate the default name for Apache SSL Certificate and Key!"
read cert

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:2048 -out $cert.key
chmod 600 $cert.key
openssl req -new -key $cert.key -out $cert.csr
openssl x509 -req -days 365 -in $cert.csr -signkey $cert.key -out $cert.crt

echo -e " The Certificate and Key for $cert has been generated!\nPlease link it to Apache SSL available website!"
ls -all /etc/httpd/ssl
exit 0

4. Change the permission of the file so that we can execute the as a command

# chmod +x /usr/local/bin/apache_ssl

Create a Self-Signed SSL Certificate

5. Run the apache_ssl file to generate the certificate files fo SSL using OpenSSL below is the sample screen where we needed to give input for some fields

# apache_ssl

mkdir: cannot create directory `/etc/httpd/ssl': File exists
Enter your virtual host FQDN:
This will generate the default name for Apache SSL Certificate and Key!
hanuman
.........................................................................................................................                             ...............................................+++
.........................................................................................................................                             ...................................................................+++
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:TELENGANA
Locality Name (eg, city) [Default City]:HYDERABAD
Organization Name (eg, company) [Default Company Ltd]:HANUMAN.COM
Organizational Unit Name (eg, section) []:HELPDESK
Common Name (eg, your name or your server's hostname) []:HELPDESK
Email Address []:XYZ@XYZ.COM

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Signature ok
subject=/C=IN/ST=TELENGANA/L=HYDERABAD/O=HANUMAN.COM/OU=HELPDESK/CN=HELPDESK/emailAddress=XYZ@XYZ.COM
Getting Private key
 The Certificate and Key for hanuman has been generated!
Please link it to Apache SSL available website!
total 32
drwxr-xr-x. 2 root root 4096 Dec 23 13:53. 
drwxr-xr-x. 5 root root 4096 Dec 17 16:28.. 
-rw-r--r--. 1 root root 1306 Dec 23 13:53 hanuman.crt
-rw-r--r--. 1 root root 1058 Dec 23 13:53 hanuman.csr
-rw-------. 1 root root 1708 Dec 23 13:52 hanuman.key


Configure Apache to Use SSL

6. We needed to edit the configuration file so that we can use SSL certificates which are generated just now

# vi /etc/httpd/conf/httpd.conf

Add the following to the file  in SSL section

SSLCertificateFile /etc/httpd/ssl/hanuman.crt
SSLCertificateKeyFile /etc/httpd/ssl/hanuman.key



To Redirect http to https 80 - 443

Add the following to the file in Virtual Host Section

<VirtualHost *:80>
    ServerName localhost servername ipaddress
    Redirect / https://ipaddress/
</VirtualHost>



# Service httpd restart

Check you website with http://your-ip-address it will redirect to https://your-ip-address


Keywords: Apache, HTTPS, Redirection, SSL, OpenSSL, Apache, Centos 6.7 

Comments

Popular posts from this blog

Observium: Configuring Microsoft Windows 2008 Server SNMP Agent

AWS: Upgrade PV Drivers on Windows Instances

How to configure Incremental backups for MSSQL Database