Friday, July 6, 2018

Configure EC2 Instance Apache Web Server on Amazon Linux 2 to Use SSL/TLS

step: 1

[ec2-user~] sudo yum update -y

Now that Your Instance is current , add SSL/TLS suppport by installing the Apache Module mod_ssl


Pre-Request

Configure your security group to allow your instance to accept connections on the following TCP ports:

SSH (port 22)
HTTP (port 80)
HTTPS (port 443


CentOS-7.X 

[ec2-user ~]$ sudo systemctl is-enabled httpd
sudo systemctl start httpd && sudo systemctl enable httpd

CentOS-6.X

Step 2

sudo yum install mod24_ssl

It have been installed mod_ssl TO configure an Modssl

The configuration file for mod_ssl. It contains "directives" telling Apache where to find encryption keys and certificates


Copy your existing SSL certificate to below mentioned path .

/etc/pki/tls/certs/example_domainname_com-ca.crt
/etc/pki/tls/private/example_domainname_com.key
/etc/pki/tls/certs/example_domainname_com.crt

/etc/httpd/conf.d/example.domainname.com.conf
________________________________________________________________________________
### trial.example.com - GENERATED AUTOMATICALLY ###
<VirtualHost *:80>
    ServerName trial.example.com
    ServerAlias www.trial.example.com
    DocumentRoot /var/www/vhosts/trial.example.com/webapp/public_html
    #Redirect permanent / https://trial.example.com/
    #RedirectMatch ^((?!\/(\/jsp\/viewReportData.jsp)).*)$ https://%{HTTP_HOST}$1

RewriteEngine On

# Go to https if not on /your-page-url/

RewriteCond %{SERVER_PORT} =80
RewriteCond %{THE_REQUEST} !/jsp/viewReportData.jsp [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


    CustomLog /var/www/vhosts/trial.example.com/statistics/logs/access_log combined
    ErrorLog  /var/www/vhosts/trial.example.com/statistics/logs/error_log

    <Directory /var/www/vhosts/trial.example.com/webapp/public_html>
        Options -Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
       JkMount /* myworker
</VirtualHost>

<VirtualHost *:443>
    ServerName trial.example.com
    ServerAlias www.trial.example.com
    DocumentRoot /var/www/vhosts/trial.example.com/webapp/public_html

RewriteEngine On

# Go to http if on /your-page-url/

RewriteCond %{SERVER_PORT} !=80
RewriteCond %{THE_REQUEST} /jsp/viewReportData.jsp [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    SSLEngine ON
    SSLCACertificateFile /etc/pki/tls/certs/trial.example.com-ca.crt
    SSLCertificateKeyFile /etc/pki/tls/private/trial.example.com.key
    SSLCertificateFile /etc/pki/tls/certs/trial.example.com.crt

    CustomLog /var/www/vhosts/trial.example.com/statistics/logs/access_ssl_log combined
    ErrorLog  /var/www/vhosts/trial.example.com/statistics/logs/error_ssl_log

    <Directory /var/www/vhosts/trial.example.com/webapp/public_html>
        Options -Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
     JkMount /* myworker
</VirtualHost>

___________________________________________________________________________________
Once the configuration file completed

Step:3

execute the below command to reflect

httpd -t

/etc/init.d/httpd restart

That it enjoy the SSL installation experience !!!

No comments:

Post a Comment