> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HTTPS

> Explains HTTPS/TLS, certificate authorities, obtaining and using certificates with Certbot or mkcert, and configuring Nginx to serve secure HTTPS for production and local development.

In this lesson you’ll learn what HTTPS is, why it matters, how TLS certificates work, and how to obtain and use them with a web server. The Nginx server block shown later demonstrates how to wire a certificate into a production-style configuration.

Why HTTPS matters

* Security: HTTPS (TLS) encrypts the entire communication channel between browser and website. On a shared network (e.g., public Wi‑Fi) an attacker cannot read intercepted traffic without access to the server’s private key. HTTPS protects usernames, passwords, payment data, and other sensitive information.
* SEO and trust: Modern search engines and browsers favor HTTPS. A secure site can rank better in search results and displays browser UI (padlock) that increases user trust.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/importance-https-coffee-shop-secure-wifi.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=fbe7f2ca47f34a893ce29dd5565fbf4d" alt="An illustrated slide titled &#x22;Importance of HTTPS&#x22; showing people in a coffee shop using laptops and Wi‑Fi, with a padlock icon and dotted lines depicting a secure (HTTPS) connection." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/importance-https-coffee-shop-secure-wifi.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/importance-https-seo-data-protection.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=d21258624108047ba8771c5070179df7" alt="A presentation slide titled &#x22;Importance of HTTPS&#x22; showing an https:// lock icon labeled &#x22;SEO Benefits.&#x22; Below it are icons and captions indicating HTTPS protects customer data and boosts visibility in search engines." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/importance-https-seo-data-protection.jpg" />
</Frame>

SSL vs TLS

* SSL (Secure Sockets Layer) is deprecated. TLS (Transport Layer Security) is the modern, secure protocol that replaced SSL.
* People still say “SSL certificate,” but the protocol in use is TLS. Use TLS 1.2 or TLS 1.3; TLS 1.0 and 1.1 (and all SSL versions) are insecure and should be disabled.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/ssl-tls-browser-server-diagram.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=32af8f45a7c948c0799e8cd89e3eab98" alt="A simple diagram titled &#x22;SSL and TLS&#x22; showing a browser icon on the left and a web server stack on the right, connected under a shield with a checkmark. The caption says the protocols ensure privacy and integrity between browser and server." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/ssl-tls-browser-server-diagram.jpg" />
</Frame>

High-level TLS handshake (simplified)

1. The browser opens an HTTPS connection to the server.
2. The server sends its TLS certificate (an X.509 document signed by a Certificate Authority). The certificate includes the server’s public key and identifying information (domain name).
3. The browser validates the certificate (chain-of-trust, expiration, and domain name). If valid, the browser and server complete an authenticated key exchange (commonly ECDHE), which results in ephemeral symmetric session keys.
4. All subsequent traffic is encrypted using the negotiated symmetric keys for performance and confidentiality.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/ssl-tls-certificate-server-to-browser.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=7cec508aba57360c177102efc3ac17cf" alt="A simple diagram showing an SSL/TLS step where a store’s web server sends its SSL/TLS certificate to a user’s browser/payment form. It features a user icon on the left, a payment form in the center, and server racks with a certificate icon on the right." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/ssl-tls-certificate-server-to-browser.jpg" />
</Frame>

Certificate Authorities (CAs)

* CAs validate identity and digitally sign certificates so browsers can trust them.
* Examples include DigiCert, Sectigo, and other commercial CAs.
* Let’s Encrypt is a widely used free, automated CA trusted by modern browsers and suitable for production.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/certificate-authority-ca-issuing-digital-cert.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=6d933aa8cb781219d1fd2aa97c327015" alt="A presentation slide titled &#x22;Certificate Authority&#x22; that shows a company/person icon issuing a digital certificate. The certificate graphic is labeled with contents like user's name, company information, and website address, and the slide notes the CA governs and manages digital certificates." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/certificate-authority-ca-issuing-digital-cert.jpg" />
</Frame>

Certificates verify ownership

* A TLS certificate is effectively a website’s online ID card. It proves the certificate requester controls the domain and prevents impersonation.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/ssl-certificate-browser-onlinestore-domain-verification.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=40257ec6c86bd4b8e6fed24aa37d7aa0" alt="A slide titled &#x22;Certificates&#x22; showing a stylized browser window with the URL https://www.onlinestore.com and an SSL certificate icon. The caption notes that a certificate verifies the domain belongs to the store, not an impostor." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/ssl-certificate-browser-onlinestore-domain-verification.jpg" />
</Frame>

Public/private keys (asymmetric encryption)

* TLS uses asymmetric cryptography for authentication and key exchange: a public key (shared) and a private key (kept secret on the server).
* The public/private key pair authenticates the server and helps establish session keys; bulk encryption uses symmetric keys because symmetric algorithms are faster.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/webserver-public-key-browser-encryption.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=fac1448f8cf68ff504352db0593f2408" alt="A diagram showing a web server sending a public key (depicted by an unlocked padlock) to a browser. The browser then uses that key to encrypt the data being sent." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/webserver-public-key-browser-encryption.jpg" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/private-key-kept-secret-server.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=67520668c79bf3550611488bc2dfb818" alt="A slide titled &#x22;Private Key&#x22; showing a lock icon in a speech-bubble and a separate key icon labeled &#x22;Kept secret by the server.&#x22; It illustrates that the private key is stored confidentially on the server." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/private-key-kept-secret-server.jpg" />
</Frame>

Practical flow for a payment form

* After the TLS handshake, the browser encrypts sensitive form fields (e.g., credit card numbers) with the negotiated symmetric session keys.
* The server uses its private key and the session keys established during the handshake to decrypt and process the request.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/public-key-encryption-payment-diagram.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=e4aff21c5283a6d74a3d725561cef897" alt="A diagram illustrating how public-key encryption works in practice. It shows a browser encrypting a credit card number, sending the encrypted data to a server that decrypts it with a private key and processes the payment." width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/public-key-encryption-payment-diagram.jpg" />
</Frame>

Obtaining TLS certificates

* Let’s Encrypt + Certbot: Let’s Encrypt issues free, trusted certificates. Certbot is a popular, well-documented client to obtain and renew certificates automatically.
* Requirements: you must own (or control) the domain and have DNS pointing to the server where you run Certbot.

Example Certbot usage (adjust domains and plugin/flags for your environment):

```bash theme={null}
sudo apt update
sudo apt install certbot
# Obtain a certificate using the standalone plugin for devops.org and www.devops.org
sudo certbot certonly --standalone --preferred-challenges http -d devops.org -d www.devops.org
```

Note: package names, installation commands, and recommended Certbot plugins (e.g., `certbot-nginx`) vary by distribution. Check the Certbot documentation for platform-specific instructions: [https://certbot.eff.org](https://certbot.eff.org)

Local development / testing: mkcert

* mkcert makes short-lived, locally trusted certificates for development and testing by installing a local CA in your machine’s trust store.
* These certificates are only appropriate for local testing and should never be used for public production sites.

<Callout icon="lightbulb" color="#1CB2FE">
  mkcert installs a local CA in your OS/browser trust store so the generated certs are trusted on your development machine. It is very convenient for local HTTPS but is not a replacement for CA‑signed certificates like those from Let’s Encrypt in production.
</Callout>

Example mkcert workflow (local testing)

* Install mkcert (platform-specific) and run `mkcert --install` once to register the local CA.
* Generate certificates for one or more hostnames. Note: X.509 wildcards only match a single subdomain level (e.g., `*.example.com` matches `a.example.com` but not `a.b.example.com`).

```bash theme={null}
sudo apt install mkcert
cd /etc/ssl/private
mkcert --install
mkcert '*.example.com'
```

Sample mkcert output (representative):

```text theme={null}
Created a new certificate valid for the following names 📜
 - "*.example.com"

Reminder: X.509 wildcards only go one level deep, so this won't match a.b.example.com ℹ️

The certificate is at "./_wildcard.example.com.pem" and the key at "./_wildcard.example.com-key.pem"
```

Place the generated certificate and key into secure locations (for example, certificate into `/etc/ssl/certs/` and private key into `/etc/ssl/private/`) and reference those paths from your web server configuration.

<Callout icon="warning" color="#FF6B6B">
  Do not use mkcert-generated certificates in production. For public-facing services, always use CA-signed certificates (e.g., from Let’s Encrypt or a commercial CA).
</Callout>

Using the certificate in an Nginx server block

* After obtaining the certificate and private key, reference them in your Nginx configuration and listen on port 443 for TLS traffic.
* Example Nginx server block — adjust `server_name` and file paths to match your environment:

```nginx theme={null}
server {
    listen 443 ssl;
    server_name honda.cars.com;

    ssl_certificate /etc/ssl/certs/honda.cars.com.pem;
    ssl_certificate_key /etc/ssl/private/honda.cars.com-key.pem;

    root /var/www/honda.cars.com/html;
    index index.html;

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

After configuring Nginx, test and reload:

```bash theme={null}
sudo nginx -t
sudo systemctl reload nginx
```

Quick reference table — certificate options

| Certificate Type                  | Use Case                       | Notes                                            |
| --------------------------------- | ------------------------------ | ------------------------------------------------ |
| Let’s Encrypt                     | Production, automated          | Free, widely trusted; use Certbot for automation |
| Commercial CA (DigiCert, Sectigo) | Enterprise/extended validation | Paid options, extended features and support      |
| mkcert                            | Local development              | Installs local CA; never use in production       |

Summary

* HTTPS/TLS protects confidentiality and integrity of web traffic; it’s essential for any site handling sensitive data.
* TLS certificates are issued and validated by Certificate Authorities. Let’s Encrypt provides free, trusted certificates and Certbot is a commonly used client for obtaining and renewing them.
* Use mkcert only for local development and testing; do not use mkcert certs in production.
* After obtaining certificates, configure your web server (example shown with Nginx) to serve HTTPS on port 443, and verify with `nginx -t` and browser or SSL tools.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/5f0mE-FaFIAKk82W/images/Nginx-For-Beginners/Security/HTTPS/lets-encrypt-free-tls-certificates.jpg?fit=max&auto=format&n=5f0mE-FaFIAKk82W&q=85&s=6d7729b68935e00602681f6bf6fd66d9" alt="A presentation slide showing the Let's Encrypt logo with the heading &#x22;Several reputable Certificate Authorities include:&#x22; and a note that it &#x22;Offers free TLS certificates.&#x22;" width="1920" height="1080" data-path="images/Nginx-For-Beginners/Security/HTTPS/lets-encrypt-free-tls-certificates.jpg" />
</Frame>

Links and references

* Certbot: [https://certbot.eff.org](https://certbot.eff.org)
* Let’s Encrypt: [https://letsencrypt.org](https://letsencrypt.org)
* mkcert GitHub: [https://github.com/FiloSottile/mkcert](https://github.com/FiloSottile/mkcert)
* Nginx documentation: [https://nginx.org/en/docs/](https://nginx.org/en/docs/)

Now that you understand the concepts and commands, practice obtaining a certificate (e.g., with Certbot) and configuring Nginx to serve HTTPS for your site.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/nginx-for-beginners/module/8905470e-b1ea-48ec-b0cd-711687ce7159/lesson/a4af90be-9d47-4d0b-a285-bec7a50ef02a" />
</CardGroup>
