How to import an SSL cert in Nginx

The below guide shows you how to import an ssl cert to nginx.

First, you must have 3 files in your procession

  • The private key that was generated after creation of CSR
  • The certificate itself in .crt or p7b format
  • The ca-bundle

For easier installation, we need to convert the .p7b certificate into a .pem cert. To do so visit the website SSL converter and follow the steps to convert the file.

Once converted we need to copy the two files .pem and the private key into your Nginx server and place them somewhere in the /etc/ directory. You can create a new folder in the /etc/ directory for this purpose, something like /etc/ssl-certs. You the copy command as shown in this tutorial to move the files.

Once moved open the nginx conf file located at /etc/nginx/nginx.conf or /etc/nginx/sites-enabled/default and add the following code block:

server {
listen 443 ssl;
ssl on;
ssl_certificate /etc/ssl-certs/yourdomain_com.crt;
ssl_certificate_key /etc/ssl-certs/yourdomain.com.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5
;

# rest of server config
}

Once done, just restart the Nginx service:

sudo service nginx restart

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *