Hosting & Deployment

Apache and Nginx TLS and Redirect Troubleshooting

Diagnose TLS failures and redirect loops across CDNs, reverse proxies, Apache, Nginx, and PHP applications.

HTTPS failures and redirect loops often occur because several layers attempt to control the same request. A browser may connect to a CDN, then a reverse proxy, then Apache or Nginx, and finally the PHP application. Each layer may see a different scheme or host unless forwarding headers and canonical redirect ownership are configured consistently.

Identify the request path

Map the route from the public DNS record to the TLS terminator and origin web server. Determine which layer presents the certificate and which layer performs HTTP-to-HTTPS and hostname redirects. Avoid configuring competing redirect rules in the CDN, proxy, web server, and application without a clear order.

Inspect TLS independently

Use SNI-aware testing:

openssl s_client -connect example.com:443 -servername example.com </dev/null
curl -I http://example.com
curl -I https://example.com

Check certificate names, expiry, intermediate chain, and the selected virtual host. If the certificate is correct at the origin but wrong publicly, inspect the CDN or proxy certificate configuration.

Diagnose redirect loops

A common loop occurs when TLS terminates at a proxy but the backend believes the request is HTTP and redirects again. Configure the proxy to send the original scheme and configure the application to trust forwarded headers only from known proxy addresses. Do not trust arbitrary client-supplied X-Forwarded-Proto values.

Check each redirect hop with curl -IL and inspect the Location header. Normalize the canonical hostname and avoid contradictory www and non-www rules. Clear cached redirects only after the server-side chain is correct.

Apply changes safely

Change one layer at a time, validate Apache with apachectl configtest or Nginx with nginx -t, and reload the relevant service. Test HTTP, HTTPS, both hostnames, static assets, login callbacks, and API endpoints. Keep a rollback path and review logs from every layer. On panel-managed servers, use supported include files or control-panel settings rather than editing generated configuration directly.

Share this page Help other developers discover this resource.