webzod
account

Answer HTTP with a redirect to HTTPS on nginx

headers.redirect.http_unreachable · effort: minutes

Why it matters

Nothing answers on http://, so visitors who type the bare domain without a remembered HSTS policy may get a connection error. Answering port 80 with a permanent redirect sends them to the https site.

The fix

  1. If the site is behind Cloudflare or another CDN that connects to this server over plain http (Cloudflare Flexible mode), this redirect loops. Switch the CDN to Full (strict) first, or redirect at the CDN instead (Always Use HTTPS).
  2. Add the server below, open port 80 in the firewall, run sudo nginx -t and reload.
nginx
server {
    listen 80;
    listen [::]:80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

The examples use example.com. Replace it with your own domain.

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.