webzod
account

Fix the HTTP redirect chain on nginx

headers.redirect.http_broken · effort: minutes

Why it matters

Requests to http:// never reach a page, so visitors who type the bare domain or follow an old link get an error. One permanent redirect from http to the https address fixes it.

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. Make the port 80 server contain only the redirect below, 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.