< All Docs

Install SSL on Ubuntu server using Nginx

Create a Microhost account to try this guide with a $50 credit.

Table of Content

What is SSL?

SSL, or Secure Sockets Layer, is an Internet security technology based on encryption. It was created by Netscape in 1995 to provide privacy, authentication, and data integrity for Internet interactions. SSL is the forerunner of the current TLS encryption protocol.

A certificate that is self-signed will encrypt communications between your server and any clients. Users cannot use the certificate to automatically authenticate the identity of your server, since it is not certified by any of the trustworthy certificate authorities available in web browsers.

If you do not have a domain name linked with your server and the encrypted web interface is not user-facing, a self-signed certificate may be suitable.

Prerequisites:

apt command should be working to install packages
Internet should be working on the machine
Super user or normal user with SUDO privileges

OS and other important files:

We have used Ubuntu with Nginx server

  • Default Configuration file: /etc/nginx/nginx.conf
  • SSL Declaration file: /etc/nginx/snippets/snakeoil.conf

Steps to install the SSL:

Step 1: Install the Nginx server and start the nginx service on your Ubuntu server using the below command.

apt install nginx -y
systemctl start nginx

Step 2: Now to check whether your Nginx service is running fine or not, go to browser and search your server ip on the browser. For example: 103.127.30.250

Step 3: Now if we want to test nginx server with a sample source code. Go to the /var/www/html directory and create an index. html file and paste the content shown in the below screenshot.

Step 4: Now generate the SSL certificate files(csr) and key using below command

openssl req -new -newkey rsa:2048 -nodes -keyout domain.com.key -out domain.com.csr

Note:

  • Here you will be asked to enter a few details. So please enter them as you want.
  • The above command will create a csr and certificate key file in the current working directory.
  • In common name, for the subdomain, you must include an asterisk if you are requesting a unique wildcard SSL certificate. In such scenario, *.mydomain.com may serve as an example. Never enter any special characters in this area, including "http://", "https://", or any other variation. Never add text after the top-level domain. Your common name, for instance, should finish in.com,.net, or the other extension you are requesting.

Congratulations, a CSR file has been generated.

When getting an SSL certificate, you must copy and paste the whole contents of the CSR file to your Certificate Authority.
The lines that say "BEGIN CERTIFICATE REQUEST" and "END CERTIFICATE REQUEST" must be included.

Step 5: Now create a conf file for your website in /etc/nginx/conf.d/ with any name.

vim /etc/nginx/conf.d/sitename.conf

Make the change as shown on the below screenshot:

Note:
Parameter ‘include’ on line 4 is important because, the value of this parameter is the file where we have defined the path of our ssl certificate file and ssl certificate private key
Server name could be anything
Semicolon on ending of every line is a must

Step 6: Now open the file

/etc/nginx/spippets/snakeoil.conf

Here, in this file define the SSL certificate and SSL certificate private key path which we create on step-4, as shown below

Note:

  • You can create a new file instead of using the generic file, but make sure to fill the file with the above content
  • In case of multiple web hosting, just create another file with the appropriate content and include the file in your website’s conf file, just as we did in step-5.

Step 8: Now Restart the Nginx service and go to your browser and browse.

systemctl restart nginx
https://server IP

And now just click on "proceed to ...(safe)"

Previous Install Plesk on CentOS 7
Next Install WHM/Cpanel in Centos 7
Table of Contents