Installing SSL Certificate on NGINX

Installing an SSL certificate on NGNIX involves several steps. Here are the instructions to install an SSL certificate NGNIX.

Prerequisites

  • A server running NGINX.

  • An SSL certificate and its corresponding private key. You can obtain these from a trusted Certificate Authority (CA) or create a self-signed certificate for testing purposes.

  • To convert your .cer into different file formats, Utilize our eMudhra utility tool to seamlessly transform your files into .cer, .pfx (.p12), .jks, or .pem formats, and conveniently import zip files using our CSR tool."

1. Upload Certificate Files

First and foremost, you will need to upload the certificate files above (certificate.crt, ca_bundle.crt and private.key) to your NGINX server in a directory of your choice.

2. Upload Certificate Files

NGINX requires all .crt files to be merged in order to allow SSL installation. You will need to run the following command in order to merge your certificate.crt and ca_bundle.crt files. $ cat certificate.crt ca_bundle.crt >> certificate.crt

3. Edit Virtual Hosts File

Next, you will need to find your NGINX virtual hosts file and add some code to point it to your new SSL certificate. As soon as you have opened your virtual hosts file, create a copy of the existing non-secure server module and paste it below the original.

Please note:

  • If you need your site to be accessible through both HTTPS (secure) and HTTP (non-secure), you will need a separate server module for each connection type.

4. Add SSL Configuration

Inside the server block, add the following lines to enable SSL. Replace the file paths with the actual paths to your certificate and private key. Add the lines in bold to your virtual hosts file: server

{
    listen                     443 ssl;
    ssl                  on;
    ssl_certificate      /etc/ssl/certificate.crt; 
    ssl_certificate_key  /etc/ssl/private.key;
    server_name  your.domain.com;
    access_log   /var/log/nginx/nginx.vhost.access.log;
    error_log    /var/log/nginx/nginx.vhost.error.log;
    location     / {
    root         /home/www/public_html/your.domain.com/public/;
    index        index.html;
    }
}

5. Restart the Server

Finally, you will need to restart your NGINX server in order for your changes to come into effect. You can run the command below to restart your NGINX server: sudo /etc/init.d/nginx restart

6. Check Installation

You have completed all the required steps to install your SSL certificate. Verify that the SSL certificate is correctly installed by accessing your website or service using HTTPS. After installing your certificate, it is a good practice to test your SSL setup using various online tools to ensure everything is working correctly.

Last updated

© eMudhra. All Rights Reserved.