Friday, 29 July 2016

thumbnail

How-to-create-SSL-certificate-and-Configure-Virtualhost-on-Ubuntu-14.04-Amazon-EC2

Introduction

In this tutorial we are going to create SSL certificate for one my Ubuntu-14.04 instance and we will be using comodo free SSL certificate for 3 months. In this tutorial I have create a sub domain called test.techs2resolve.in which I pointed to my amazon instance live ip.

I have taken the sub-domain for testing purpose but if you are working with production envrionment then you have to point your main domain like e.g example.com is your main domain. And also make sure that you required www.example.com or only example.com certificate because this free trial certificate is only for one domain. Subdomain are not allowed.

As you all know that there are types of SSL certificate available :-

1. SSL with signle domain.
2. SSL with wildcard with multiple sub domain.

This tutorial assumes you have successfully installed the LAMP server in your instance.
1.Click here to install LAMP server

1. First create the Virtual host for your domain :-

cd /etc/apache2/sites-available/
cp default-ssl.conf test.techs2resolve.in-ssl.conf

2. Now create directory where you will store data :-

We need to enable userdir  for that 
Click here to enable Userdir 


Create a public_html directory in your user's home directory and change permission like below :-

mkdir public_html
chmod -R 770 public_html
chown -R username:www-data public_html

3. Next we need to create SSL certificate:-

cd /etc/ssl/private 
openssl genrsa -aes128 -out test.techs2resolve.in.key 2048   <--Enter random password 
openssl rsa -in test.techs2resolve.in.key -out test.techs2resolve.in.key 
openssl req -new -days 3650 -key test.techs2resolve.in.key -out test.techs2resolve.in.csr
openssl x509 -in test.techs2resolve.in.csr -out test.techs2resolve.in.crt -req -signkey test.techs2resolve.in.key -days 3650
chmod 400 test.techs2resolve.in.*

Now the above is self generated certificate we have to create valid ssl certificate through comodo ssl. You can use any SSL authority who is issuing free or paid.

To Create Valid SSL click the below link :-

https://ssl.comodo.com/free-ssl-certificate.php

Now Click on Free Trial SSL


Now you will see something like this below :-





Now open your domain.csr file with your favourite editor:-

sudo su
cd /etc/ssl/private
vim test.techs2resolve.in.csr

Now copy all of the content inside your file and paste in comodo ssl certificate website CSR box like below:-


Paste here below :-

 

Now we have to Select the server software which used to generate the CSR:

We have used Apache-ModSSL because we have generated through Openssl


Click on Next and fillup your domain valid details like your Email address is very important because your are going to receive a verification code on it.

So please make sure which email address you have entered during the registration of your domain and make sure your email address is working.

How to get your registered email address of your domain:-

Open the terminal and type below :-

whois yourdomainname 

After the above steps completion you will recieve your valid ssl certificate on your mail. Copy the certificate zip file to your server through "scp".

3. Now you have to move that certificate to /etc/ssl/private directory

sudo cp -av test_techs2resolve_in.zip /etc/ssl/private
cd /etc/ssl/private 
unzip test_techs2resolve_in.zip 

4. Now configure conf file which you have created earlier in step 1 like below :-

sudo vim /etc/apache2/sites-available/test.techs2resolve.in-ssl.conf

The following parameter you need to change :-


ServerAdmin sarfaraz@techs2resolve.in
ServerName test.techs2resolve.in
DocumentRoot /home/sarfaraz/public_html
ErrorLog /var/log/test.techs2resolve.in/error.log
CustomLog /var/log/test.techs2resolve.in/access.log combined
SSLCertificateFile      /etc/ssl/private/test_techs2resolve_in.crt
SSLCertificateKeyFile /etc/ssl/private/test.techs2resolve.in.key
SSLCertificateChainFile /etc/ssl/private/test_techs2resolve_in.ca-bundle


Create Log directories :-

sudo mkdir /var/log/test.techs2resolve.in/
sudo touch /var/log/test.techs2resolve.in/error.log /var/log/test.techs2resolve.in/access.log
chmod -R 777 /var/log/test.techs2resolve.in/

5. Now we need disable default ssl site :-

sudo a2dissite default-ssl
 
Enable your site :-

sudo a2ensite test.techs2resolve.in-ssl.conf

Enable Mod SSL :-

sudo a2enmod ssl

Restart the Apache2 service :-

sudo service apache2 restart

6. Now test on your browser :-

https://test.techs2resolve.in

That's it
Enjoy using it 
Please do Likes,Comment and Share

Related Posts :

Subscribe by Email

Follow Updates Articles from This Blog via Email

No Comments