When HTTPS terminates at the proxy but the backend assumes HTTP, redirects can loop or links can point to the wrong origin. Align path mapping, Location rewriting and forwarded-header trust as one deployment contract.
Scope and prerequisites
Require proxy, proxy_http and headers modules. Merge the example into an already-valid HTTPS virtual host; it does not replace TLS configuration. The backend is assumed at 127.0.0.1:8080 and should not be exposed unnecessarily. Applications under /app also need compatible base URLs and asset paths.
1. Collect evidence
Record Location and host behavior without blindly following unlimited redirects. Compare direct backend responses from the proxy host. Both layers may force HTTPS, or the application may store an internal base URL. ProxyPassReverse fixes relevant redirect headers, not every URL embedded in HTML or JavaScript.
curl -sI https://example.com/app/
curl -sI -H "Host: example.com" http://127.0.0.1:8080/
apachectl -M | grep -E "proxy|headers"
2. Make a controlled change
ProxyRequests Off prevents accidentally enabling a forward proxy. In the HTTPS virtual host, overwrite X-Forwarded-Proto with trusted https. Configure the backend to trust forwarded headers only from defined proxies. Match trailing-slash behavior on both sides of ProxyPass and derive path mapping from the application contract.
# Inside the existing HTTPS VirtualHost ONLY; retain certificate settings.
ProxyRequests Off
ProxyPreserveHost On
RequestHeader set X-Forwarded-Proto "https"
ProxyPass "/app/" "http://127.0.0.1:8080/"
ProxyPassReverse "/app/" "http://127.0.0.1:8080/"
3. Verify the outcome
Run configtest and reload, then test login, redirects, assets and slashless paths. Responses should not expose internal hostnames or the wrong scheme. Inspect cookie domains and paths and add scoped reverse-cookie rewriting only if needed. WebSocket tunneling is a separate requirement and not established by a working HTTP page.
sudo apachectl configtest
# Debian/Ubuntu: use the actual service name on other distributions.
sudo systemctl reload apache2
curl -sI https://example.com/app/
curl -sI https://example.com/app
Rollback and prevention
Rollback the virtual-host change and backend trust configuration together. Document trusted headers and backend network access; never create a public forward proxy. Monitor redirect counts and 502/503 rates after deployment. Larger timeouts cannot fix redirect loops or an incorrect base URL.
Technical references
For related checks in this workflow, see Configure WebSockets Behind Nginx and Fix Upgrade Failures and Restore Real Client IPs Behind a Trusted Proxy in Nginx.
