Operating a website over plain HTTP in modern web engineering is obsolete. Browsers flag unencrypted sites as “Not Secure,” modern web APIs (including Geolocation, Service Workers, Web Cryptography, and HTTP/2/3) refuse to execute over unencrypted channels, and search engines penalize unencrypted domains in ranking algorithms.

However, moving from plain HTTP to properly configured, secure HTTPS involves more than just toggling an SSL certificate. Engineers must understand TLS handshakes, manage automatic certificate renewals, configure canonical 301 redirects, implement HTTP Strict Transport Security (HSTS), and resolve certificate mismatches.

This guide provides a thorough, practical walkthrough for configuring end-to-end HTTPS, hardening your security posture, and diagnosing the most common production TLS errors.


How TLS 1.3 Encryption Works

Transport Layer Security (TLS)—the successor to the deprecated Secure Sockets Layer (SSL)—provides three essential guarantees:

  1. Confidentiality (Encryption): Prevents third parties on the network path from intercepting or reading transmission data.
  2. Integrity: Ensures packets cannot be tampered with or altered in transit without detection.
  3. Authentication: Verifies that the client is actually communicating with the legitimate owner of the domain.

TLS 1.3 streamlines the handshake into a single round trip (1-RTT), dramatically reducing connection latency compared to TLS 1.2:

Client                                                   Server
  |                                                         |
  |  1. ClientHello (Supported ciphers, Key Share)          |
  |-------------------------------------------------------->|
  |                                                         |
  |  2. ServerHello (Selected cipher, Key Share)            |
  |     Server Certificate (Signed by Trusted CA)           |
  |     CertificateVerify                                   |
  |     Finished (Symmetric encryption begins)              |
  |<--------------------------------------------------------|
  |                                                         |
  |  3. Finished & First Encrypted HTTP Request             |
  |-------------------------------------------------------->|
  |                                                         |
  |  4. Encrypted HTTP Response                             |
  |<--------------------------------------------------------|

The server and client exchange ephemeral Diffie-Hellman keys to derive symmetric session keys. Even if the server’s private key were compromised years later, past traffic cannot be retroactively decrypted (a property known as Forward Secrecy).


Certificate Types and Selection

When acquiring an SSL/TLS certificate, there are three primary validation levels:

Validation Level Verification Process Best Use Case
Domain Validation (DV) Automated proof of domain control via DNS record or HTTP file token. Standard websites, SaaS applications, blogs, and APIs.
Organization Validation (OV) Automated domain check + legal verification of company identity. Enterprise portals, B2B platforms.
Extended Validation (EV) Exhaustive legal and operational vetting. High-security financial institutions.

For virtually all web applications and static sites, Domain Validated (DV) certificates provide the identical 256-bit AES cryptographic strength as EV certificates without recurring bureaucratic verification overhead.


Method 1: Automated HTTPS with Let’s Encrypt and Certbot (Nginx)

For self-hosted Linux servers running Nginx, the Electronic Frontier Foundation’s Certbot automates certificate issuance, web server configuration, and cron-based renewals via the ACME protocol.

Step 1: Install Certbot and the Nginx Plugin

On Ubuntu/Debian:

sudo apt update
sudo apt install -y certbot python3-certbot-nginx

Step 2: Configure the Nginx Server Block

Ensure your Nginx configuration specifies your domain in server_name:

# /etc/nginx/sites-available/flovo-site
server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

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

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

Enable the configuration and verify syntax:

sudo ln -s /etc/nginx/sites-available/flovo-site /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Step 3: Issue and Install the Certificate

Run Certbot targeting Nginx:

sudo certbot --nginx -d example.com -d www.example.com

Certbot verifies domain control, retrieves the signed certificate chain, modifies your Nginx configuration to add SSL directives, and installs automatic HTTP-to-HTTPS redirects.

Step 4: Verify Automated Renewal

Let’s Encrypt certificates are valid for 90 days. Certbot installs a systemd timer that tests renewal twice daily:

# Run a dry-run renewal test
sudo certbot renew --dry-run

Method 2: Edge-Terminated HTTPS (Cloudflare)

When using an edge proxy or CDN like Cloudflare, the TLS handshake terminates at the nearest edge server:

Browser <--- (Edge SSL) ---> Cloudflare Edge <--- (Origin SSL) ---> Origin Server

Understanding Cloudflare SSL/TLS Encryption Modes

Navigating to Cloudflare Dashboard > SSL/TLS > Overview, you are presented with encryption modes:

  • Off: No encryption. All traffic uses plaintext HTTP.
  • Flexible: Encrypts traffic between browser and Cloudflare edge, but transmits traffic from Cloudflare to your origin over unencrypted HTTP (port 80).

    Warning: Never use Flexible mode in production. It creates a false sense of security, leaves origin traffic vulnerable to interception, and frequently triggers infinite redirect loops.

  • Full: Encrypts traffic end-to-end, but accepts self-signed certificates at the origin.
  • Full (Strict): The recommended Flovo standard. Requires a valid, unexpired, trusted certificate installed at the origin server.

Enforcing Canonical HTTPS Redirects

All HTTP requests must receive an immediate 301 Moved Permanently response directing traffic to the HTTPS version.

Nginx Configuration

server {
    listen 80;
    listen [::]:80;
    server_name example.com www.example.com;

    # 301 Permanent Redirect to HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com www.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 HIGH:!aNULL:!MD5;

    root /var/www/example.com/public;
    index index.html;
}

Apache .htaccess Configuration

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

Hardening with Security Headers

A basic HTTPS setup still leaves vulnerabilities open if browsers are allowed to downgrade connections. Implement the following response headers:

1. HTTP Strict Transport Security (HSTS)

Instructs the browser to only connect to this domain using HTTPS for the specified duration (e.g., 1 year), completely refusing to send plaintext HTTP:

Strict-Transport-Security: max-age=31536000; includeSubDomains; preload

2. Upgrading Insecure Requests

Instructs the browser to automatically treat any HTTP asset links on the page as HTTPS before fetching them:

Content-Security-Policy: upgrade-insecure-requests;

Troubleshooting Common Production HTTPS Errors

1. ERR_TOO_MANY_REDIRECTS (Infinite Redirect Loop)

  • Symptom: The browser displays a redirect loop error when accessing https://example.com.
  • Root Cause: Cloudflare is set to Flexible SSL mode. The browser requests HTTPS, Cloudflare accepts it, then contacts the origin server over HTTP. The origin server sees an HTTP request and sends a 301 redirect back to HTTPS. The cycle repeats indefinitely.
  • Fix: Switch Cloudflare SSL/TLS mode to Full (Strict) and configure your origin server with a valid certificate.

2. NET::ERR_CERT_COMMON_NAME_INVALID

  • Symptom: Certificate error stating the certificate does not match the requested hostname.
  • Root Cause: You visited https://www.example.com, but the certificate was only issued for example.com (missing Subject Alternative Names).
  • Fix: Reissue the certificate specifying all subdomains: certbot --nginx -d example.com -d www.example.com.

3. Mixed Content Warnings (Blocked loading mixed active content)

  • Symptom: The padlock icon displays an exclamation mark or disappears. Scripts, fonts, or images fail to load.
  • Root Cause: An HTML page loaded over HTTPS contains hardcoded asset URLs pointing to http://.
  • Fix: Update hardcoded URLs in your templates and CSS to use relative paths (/images/logo.png) or protocol-relative/HTTPS URLs. Add the Content-Security-Policy: upgrade-insecure-requests header.

4. NET::ERR_CERT_DATE_INVALID

  • Symptom: Browser reports the certificate has expired or is not yet valid.
  • Root Cause: Automated renewal daemon failed (e.g. firewall blocked ACME challenge on port 80), or the server system clock is drifted.
  • Fix: Check certbot renew output and verify renewal logs in /var/log/letsencrypt/letsencrypt.log.

Verifying Your SSL Configuration

Test your deployment from the command line using curl:

# Verify HTTP to HTTPS 301 Redirect
curl -I http://example.com

# Verify TLS connection details and cipher suite
curl -Iv https://example.com

To perform a comprehensive cryptographic audit, run your domain through the Qualys SSL Labs Test. A properly configured server with TLS 1.2/1.3, strong cipher suites, and active HSTS will reliably achieve an A+ security grade.