DEV Community

Cover image for Add SSL Cert to Nginx

Posted on

Add SSL Cert to Nginx

Add SSL Cert to Nginx

This tutorial will go over how to add a Namecheap ssl certification to your nginx web server.


Purchased Namecheap Domain name + SSL

Server is remote accessible with proper software installed

Create SSL Certification


The path the to certs will need to be referenced later in the nginx config.

This example will be using /root as the path.

# Key


# SSL Bundle

# SSL Cert

Generate CSR

A certificate signing request (CSR) generated by openssl will be used to initialize the process.

  • newKey rsa:2048
    • Generates new private key and cert
    • Using rsa:2048
  • nodes
    • Does not encrypt private key
  • keyout /$PATH/
  • out /$PATH/
openssl req \
    -newkey rsa:2048 \ 
    -nodes \
    -keyout \

Submit to Namecheap

Use cat to output the value of the csr.

Copy the content and paste it to the Namecheap SSL Vendor CSR step.


Download SSL Bundle

The SSL vendor will email you a SSL bundle which will used to create your SSL cert.


Copy the content form and paste it into your server to a file called inermediate.crt using nano

nano intermediate.crt

Copy the content form and paste it into your server to a file called


Combine the content from both certs into one file by using cat and the redirect > commands

cat intermediate.crt >

Nginx Default Config

Run cat /etc/nginx/sites-enabled/default to see the config that will be edited.

Redirect HTTP:80 -> HTTPS:443

server {
    listen 80;
    rewrite ^/(.*)$1 permanent;

Listen HTTPS:443

server {
    listen 443 ssl;

    ssl_certificate /root/;
    ssl_certificate_key /root/;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    root /var/www;
    index index.html;

    location / {}

Restart Nginx

Verify your changes
nginx -t
Restart Server
service nginx restart

Top comments (0)