Mon, March 30, 2020 · 2 min read

How to add SSL certificate provided by GoDaddy to a website running on Nginx?

How to add SSL certificate provided by GoDaddy to a website running on Nginx?

Introduction

This tutorial will show you how to acquire and install an SSL certificate from a trusted, commercial Certificate Authority (CA). SSL certificates allow web servers to encrypt their traffic, and also offer a mechanism to validate server identities to their visitors.

Certificate Types

There are 3 types of SSL Certificate available:

  • Single Domain: Used for a single domain, e.g. test.com.
  • Wildcard: Used for a domain and any of its subdomains.
  • Multiple Domain: Known as a SAN or UC certificate, these can be used with multiple domains.

Generate a CSR and private Key

To generate a certificate signing request (CSR):

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

This will generate 2 files (.key and .csr).

Go to GoDaddy’s SSL certificate page and register for the ssl certificate by providing the generated .csr file.

Next download the ssl certificate from GoDaddy, select the server type as nginx and download the Zip file.

Once the zip is extracted you should get 2 files: one will be 1235454xxxx.crt and another will look like gd.bundle-g2-1.crt.

Rename the files accordingly and combine them:

cat test.com.crt intermediate.crt > new.test.crt

Now configure Nginx:

listen 443 ssl;
servername test.com
ssl_certificate /etc/nginx/ssl/new.test.crt
ssl_certificate_key /etc/nginx/ssl/test.com.key

If you want HTTP traffic to redirect to HTTPS:

server {
    listen 80;
    servername test.com
    rewrite ^/(.*) https://test.com/$1 permanent;
}

Check configuration and restart nginx:

sudo nginx -T
sudo service nginx restart