How to Install an SSL Certificate on Nginx (Ubuntu and Debian)

Installing an SSL certificate on Nginx

How to Install an SSL Certificate on Nginx (Ubuntu and Debian)

Combine your certificate and intermediate, add a 443 server block, redirect HTTP to HTTPS and check the chain on Ubuntu or Debian.

To install an SSL certificate on Nginx, combine your certificate and DigiCert’s intermediate certificate into one file, point the ssl_certificate and ssl_certificate_key directives in your server block at that file and your private key, test the configuration, and reload Nginx. The whole job takes about ten minutes.

This guide covers Nginx on Ubuntu 22.04, Ubuntu 24.04 and Debian 12 on a Cloud VPS Hosts VPS or dedicated server. It works for RapidSSL, GeoTrust and DigiCert certificates bought from our store.

What do you need before you start?

You need three things on the server: the private key you created with your CSR, your issued certificate, and the intermediate (CA bundle) certificate.

  • Your private key, for example /etc/ssl/private/example.com.key. If you have not created it yet, follow How to generate a CSR first.
  • Your certificate file, usually named after your domain, such as example_com.crt.
  • The intermediate certificate, usually named DigiCertCA.crt or provided as a CA bundle.
  • SSH access with sudo, and Nginx already serving your site on port 80. If Nginx is not installed yet, follow How to install Nginx on Ubuntu first.

You can download the issued certificate files at any time from your certificate’s page under Services > My Services in the client area.

How do you upload the certificate files to the server?

Copy the certificate and intermediate files into /etc/ssl/certs/. From your own computer, scp works well:

scp example_com.crt DigiCertCA.crt root@your-server-ip:/etc/ssl/certs/

If you only have the certificate text, create the file on the server and paste it in:

sudo nano /etc/ssl/certs/example_com.crt

Paste everything from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE-----, then save with Ctrl+O and exit with Ctrl+X.

How do you build the certificate chain file for Nginx?

Nginx expects your certificate and the intermediate certificate together in one file, with your certificate first. Join them with cat:

cd /etc/ssl/certs
sudo sh -c 'cat example_com.crt DigiCertCA.crt > example.com.chained.crt'

The order matters. If the intermediate comes first, Nginx will refuse to start with a key mismatch error.

Before going further, confirm that the certificate matches your private key. The two commands below must print the same value:

openssl x509 -noout -modulus -in /etc/ssl/certs/example_com.crt | openssl md5
sudo openssl rsa -noout -modulus -in /etc/ssl/private/example.com.key | openssl md5

If they differ, the certificate was issued for a different CSR. Reissue it with the CSR that belongs to this key.

How do you configure the Nginx server block for SSL?

Add a server block that listens on port 443 and points to your chain file and private key. Open your site’s configuration file:

sudo nano /etc/nginx/sites-available/example.com

Add a block like this, adjusting the domain, paths and document root to match your site:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name example.com www.example.com;

    ssl_certificate     /etc/ssl/certs/example.com.chained.crt;
    ssl_certificate_key /etc/ssl/private/example.com.key;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 1d;

    root /var/www/example.com;
    index index.html index.php;

    location / {
        try_files $uri $uri/ =404;
    }
}

The default Nginx packages in Ubuntu 22.04, Ubuntu 24.04 and Debian 12 are older than 1.25.1 and use the listen 443 ssl http2; syntax shown above. If you installed a newer Nginx from nginx.org, it prints a deprecation warning for that syntax. In that case write listen 443 ssl; and add a separate http2 on; line. Check your version with nginx -v.

If your site runs PHP, copy your existing location ~ \.php$ block from the port 80 configuration into this block.

How do you redirect HTTP to HTTPS?

Replace your existing port 80 server block with a redirect, so every visitor lands on the secure version:

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

If you plan to use HTTP file validation for future reissues, make sure https://example.com/.well-known/pki-validation/ serves files from your document root. With the configuration above, it does.

How do you test and reload Nginx?

Always test the configuration before reloading. A syntax error with a plain restart takes every site on the server offline.

sudo nginx -t
sudo systemctl reload nginx

If nginx -t reports “syntax is ok” and “test is successful”, the reload is safe. If you use UFW, open HTTPS as well:

sudo ufw allow 'Nginx Full'

How do you check that SSL is working?

Open https://example.com in a browser and click the padlock to view the certificate. Then run a test from the command line that shows the full chain:

openssl s_client -connect example.com:443 -servername example.com </dev/null | grep -E "subject=|issuer=|Verify return code"

“Verify return code: 0 (ok)” means the chain is complete. For a detailed report, run your domain through the free Qualys SSL Labs test.

How do you fix errors when you install an SSL certificate on Nginx?

Error Likely cause Fix
key values mismatch Wrong key for this certificate, or the chain file has the intermediate first Run the modulus check above and rebuild the chain with your certificate first
Browser shows “certificate not trusted” on some devices Intermediate certificate missing from the chain file Rebuild example.com.chained.crt with both files
cannot load certificate key ... Permission denied Wrong permissions or path Check the path and run sudo chmod 600 on the key
HTTPS times out Port 443 blocked by the firewall Run sudo ufw allow 'Nginx Full'
Old certificate still shows Nginx was not reloaded, or another server block on 443 wins Reload Nginx and check for duplicate server_name entries with sudo nginx -T

Need a server for your site first? Our Linux VPS plans come with full root access, so you can run Nginx exactly the way this guide describes.

Frequently asked questions

Do I need to restart Nginx, or is a reload enough?

A reload is enough. systemctl reload nginx loads the new certificate without dropping open connections.

How do I install a Wildcard certificate on Nginx?

Exactly the same way. Use the same chain file in every server block for a subdomain the wildcard covers, such as shop.example.com and blog.example.com.

How often do I need to reinstall the certificate?

DigiCert certificates issued since March 15, 2026 are valid for up to 199 days. Before expiry, reissue the certificate from the client area, replace the files, rebuild the chain file and reload Nginx. Your nginx configuration does not change if you keep the same file names.

Can I use both Let’s Encrypt and a paid certificate?

Not on the same domain at the same time. If Certbot manages the domain, remove its lines from your server block and stop its renewal for that domain, or Certbot may overwrite your configuration.

Post Your Comment

Knowledgebase
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.