Skip to content

How to Install SSL on nginx

Key idea:

Installing SSL on nginx in 15 min with Let's Encrypt: certbot automatically modifies the config + enables HTTPS + adds HTTP→HTTPS redirect. For manual control — copy fullchain.pem + privkey.pem into /etc/ssl/, add an ssl block to the server config, enable HSTS + modern ciphers.

Below: step-by-step, working examples, common pitfalls, FAQ.

Check your site's SSL →

Step-by-Step Setup

  1. Install certbot + plugin: apt install certbot python3-certbot-nginx
  2. Ensure the domain resolves to the server (A record)
  3. Auto-install: certbot --nginx -d example.com -d www.example.com
  4. Certbot will ask about HTTP→HTTPS redirect (always yes)
  5. Verify: curl -I https://example.com → HTTP/1.1 200 OK
  6. Enable auto-renew: systemctl enable --now certbot.timer
  7. Test: Enterno SSL → grade A+ with proper cipher suite

Working Examples

ScenarioConfig
nginx ssl block (manual)server { listen 443 ssl http2; server_name example.com; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256; }
HTTP→HTTPS redirectserver { listen 80; server_name example.com; return 301 https://$host$request_uri; }
HSTS header (preload-ready)add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
OCSP Staplingssl_stapling on; ssl_stapling_verify on; ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem; resolver 1.1.1.1 valid=60s;
Pre-installed cert (not Let's Encrypt)# cat cert.pem intermediate.pem > fullchain.pem ssl_certificate /etc/ssl/fullchain.pem; ssl_certificate_key /etc/ssl/private.key;

Common Pitfalls

  • Using only cert.pem (no intermediate) → ERR_CERT_AUTHORITY_INVALID for clients
  • Missing OCSP Stapling → -10 points in Qualys SSL Labs grade
  • Weak ciphers (RC4, 3DES) → grade F + Chrome ERR_SSL_VERSION_OR_CIPHER_MISMATCH
  • HSTS without testing — if something breaks, clients are locked out for weeks
  • Port 80 closed by firewall — certbot renewal fails (HTTP-01 challenge)

TL;DR

To install an SSL certificate on Nginx, obtain your certificate files, then modify the Nginx configuration file to include the paths to your SSL certificate and private key. Use the listen 443 ssl; directive to enable SSL, and test the configuration before reloading Nginx. This ensures secure HTTPS connections for your website.

Step-by-Step Guide to Installing an SSL Certificate on Nginx

Installing an SSL certificate on Nginx involves several specific steps to ensure your server is correctly configured for secure connections. Below, we provide a detailed walkthrough of these steps, including practical commands and configurations.

Prerequisites

Before you start, ensure that you have:

  • Access to your Nginx server (root or sudo privileges).
  • An SSL certificate and its corresponding private key. You can obtain these from a Certificate Authority (CA) or generate a self-signed certificate for testing purposes.
  • The Nginx web server installed and running on your server.

Step 1: Obtain Your SSL Certificate

If you haven't already obtained an SSL certificate, you can purchase one from a trusted CA like Let's Encrypt, DigiCert, or Comodo. If you're testing, you can create a self-signed certificate with the following commands:

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/mydomain.key -out /etc/ssl/certs/mydomain.crt

This command generates a private key and a self-signed certificate valid for one year.

Step 2: Configure Nginx for SSL

Next, you need to configure Nginx to use your SSL certificate. Open the Nginx configuration file for your site, typically located at /etc/nginx/sites-available/default or a similar path depending on your setup:

sudo nano /etc/nginx/sites-available/default

In the server block, add the following lines:

server {
listen 443 ssl;
server_name mydomain.com www.mydomain.com;
ssl_certificate /etc/ssl/certs/mydomain.crt;
ssl_certificate_key /etc/ssl/private/mydomain.key;
location / {
try_files $uri $uri/ =404;
}
}

Replace mydomain.com with your actual domain name, and ensure the paths to your certificate and key files are correct.

Step 3: Redirect HTTP Traffic to HTTPS

For better security, it’s advisable to redirect all HTTP traffic to HTTPS. You can add another server block to your configuration file:

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

This configuration listens on port 80 and redirects any requests to the equivalent HTTPS URL.

Step 4: Test Your Configuration

Before reloading Nginx, check your configuration for syntax errors:

sudo nginx -t

If the test is successful, you will see a message indicating the configuration is okay. If there are errors, fix them as indicated.

Step 5: Reload Nginx

Once your configuration is error-free, reload Nginx to apply the changes:

sudo systemctl reload nginx

Step 6: Verify SSL Installation

To confirm that your SSL certificate is installed correctly, you can use tools like SSL Labs' SSL Test (ssllabs.com) or simply navigate to your website using https://. Look for the padlock symbol in the browser's address bar, indicating a secure connection.

Conclusion

By following these steps, you can successfully install an SSL certificate on your Nginx server, enhancing the security of your website and ensuring encrypted connections for your users. Regularly check your SSL certificate's validity and renew it as needed to maintain secure communications.

CertificateExpiry, issuer, domains (SAN)
ChainIntermediate and root CA validation
TLS ProtocolTLS version and cipher suite
VulnerabilitiesHeartbleed, POODLE, weak ciphers

Why teams trust us

TLS 1.3
supported
Full
CA chain check
<2s
result
30/14/7
days-to-expiry alerts

How it works

1

Enter domain

2

TLS chain verified

3

Expiry date & vulnerabilities

What Does the SSL Check Cover?

SSL/TLS is the encryption protocol that protects data between the browser and server. Our tool analyzes the certificate, chain of trust, TLS version, and knownvulnerabilities.

Certificate Details

Issuer, validity period, signature algorithm, covered domains (SAN), and validation type (DV/OV/EV).

Chain of Trust

Full chain verification: from leaf certificate through intermediates to root CA.

TLS Analysis

Protocol version (TLS 1.2/1.3), cipher suites, Perfect Forward Secrecy (PFS) support.

Expiry Alerts

Set up a monitor — get Telegram and email alerts 30/14/7 days before expiration.

DV vs OV vs EV Certificates

DV (Domain Validation)
  • Confirms domain ownership only
  • Issued in minutes automatically
  • Free via Let's Encrypt
  • Suitable for most websites
  • Most common certificate type
OV / EV
  • Organization (OV) or Extended Validation (EV)
  • Issued in 1-5 business days
  • Costs $50 to $500/year
  • For finance, e-commerce, government sites
  • Increases user trust

Who uses this

DevOps

SSL certificate monitoring

Security

TLS config audit

SEO

HTTPS as ranking factor

E-commerce

customer trust

Common Mistakes

Expired certificateBrowsers block sites with expired SSL. Set up auto-renewal or monitoring.
Incomplete certificate chainWithout intermediate CA, some browsers and bots cannot verify the certificate.
Mixed content on HTTPS siteHTTP resources on an HTTPS page — the browser lock icon disappears, reducing trust.
Using TLS 1.0/1.1Legacy TLS versions have known vulnerabilities. Use TLS 1.2+ or 1.3.
Domain mismatch in certificateThe certificate must cover all site domains, including www and subdomains.

Best Practices

Set up auto-renewalLet's Encrypt + certbot with cron — certificate renews automatically every 60-90 days.
Enable HSTSStrict-Transport-Security header forces browsers to always use HTTPS.
Use TLS 1.3TLS 1.3 is faster (1-RTT handshake) and safer — legacy ciphers removed.
Monitor expiration datesCreate a monitor on Enterno.io — get notified well before expiration.
Verify chain after renewalAfter certificate renewal, confirm that intermediate certificates are installed.

Get more with a free account

SSL certificate monitoring, check history and alerts 30 days before expiry.

Sign up free

Learn more

Frequently Asked Questions

Is Let's Encrypt good for production?

Yes, 100%. Google, Facebook, Cloudflare use it. Only constraint: 90 days validity (auto-renew handles that).

How to install a commercial CA cert?

Same as manual: fullchain.pem = cert + intermediate, separate privkey.pem. In nginx — ssl_certificate + ssl_certificate_key.

Certbot edits my config — safe?

Yes. Certbot keeps a backup. You can revert: <code>cp nginx.conf.backup nginx.conf</code>.

How to auto-renew?

systemctl enable --now certbot.timer. Runs twice daily. Renew hook: <code>--deploy-hook "systemctl reload nginx"</code>.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.