How to Setup a SSL Certificate in Nginx

How to Setup a SSL Certificate in Nginx

Knowing how to setup a SSL Certificate in Nginx is important as this web server is efficient in providing services for your various needs. This is a great platform for improving your sites as well as doing various jobs such as load balancing. So, it is important to know how to install SSL Certificate from this platform.

Installing Certificates in Nginx ngix ssl cert

If you want to know how you can protect your site using certificates, here is a quick way on how to install your SSL Certificate in Nginx.

  • Download the Certificate Files

Once you have purchased an SSL Certificate from a certified and trusted certificate authority, download the certificate files on your computer. You can either download it from a link or directly from that email from the certificate authority where you purchased your certificates.

Be sure that the certificate files are saved in an accessible and secured place to ensure the security of your website.

  • Installation

After ensuring that your SSL Certificate files are saved in a secure place, you can now install it in Nginx. First, you have to stack your SSL Server Certificate on top of your intermediate certificate file. To do this, you need to execute this command:

cat GeoTrust_Intermediate.txt >> your_domain_com.txt

The next step will be changing the filename of your certificate from ‘your_domain_com.txt’ to ‘your_domain_com.crt’.

  • Updating the Configuration File

After renaming your certificate filename, you have to configure the Nginx configuration file. This is done by finding your Nginx configuration file and providing the concatenated SSL Server Certificate file and your private key. Run the following command:

worker_processes 1;
http {
  server {
    listen               443;
    ssl                  on;
    ssl_certificate      /usr/local/nginx/conf/your_domain_com.crt;
    ssl_certificate_key  /usr/local/nginx/conf/cert.key;
    keepalive_timeout    70;
  }
}

If you are using the Nginx 0.7.14 version, you need to execute this command since the version enables SSL by the ‘listen’ directive using the ‘ssl’ parameter:

server {
  listen 443 default ssl;
  ssl_certificate      /usr/local/nginx/conf/your_domain_com.crt;
  ssl_certificate_key  /usr/local/nginx/conf/cert.key;  
  ...
}
  • Determining Errors

Before you restart Nginx to finish the setup, you need to check if there are any errors on the installation process. To do this, implement the following command:

sudo nginx -t -c /etc/nginx/nginx.conf

  • Restarting the System

If there are no errors on the installation process, you can now restart the system to finish the setup. Run this command:

sudo /etc/init.d/nginx restart

After the restart, the certificate should be properly installed by now.

After installing and configuring the SSL Certificate on Nginx, you should check if the certificate is working by using certificate installation checkers. This will determine if the installation is successful and if there are any errors on your site. You can also visit your site to see if the certificate is working properly.

If you find any errors, it is best to check Nginx and call for customer support so that they can assist you in the reinstallation process if you cannot resolve the issue on your own. This is also advisable if you have only been using Nginx for some time now or if you have just installed a certificate for the first time.

Previous post:

Next post: