Rails ActionController::InvalidAuthenticityToken Behind Reverse Proxy

Nginx omitted `X-Forwarded-Proto https`, causing Rails origin check to fail.

Runs locally in browser Free · No login Independently Verified 2026-11-25 v4.1.0
Identifier: Rails ActionController Platform: Ruby
Common Root Causes:
  • Nginx omitted `X-Forwarded-Proto https`, causing Rails origin check to fail.

Interactive Diagnostic Checklist

Verified Solutions:
  1. Pass `proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host;` from Nginx.
Safe Diagnostic Command:
Inspect Nginx proxy_set_header X-Forwarded-Proto
Warning: Verify configuration changes in staging or with dry-run flags (e.g. nginx -t) before reloading production services.

Technical Explanation

Nginx omitted `X-Forwarded-Proto https`, causing Rails origin check to fail. Recommended diagnostic: `Inspect Nginx proxy_set_header X-Forwarded-Proto`. Remediation: Pass `proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $host;` from Nginx.

Worked Examples

  • Run `Inspect Nginx proxy_set_header X-Forwarded-Proto` to verify root cause before applying the remediation.

Limitations & Assumptions

  • Always verify configuration changes in staging or with dry-run flags (e.g. `nginx -t`) before reloading production services.

Source References & Verification

Resource ID: err-rails-invalidauthenticitytoken-csrf · Independently verified: 2026-11-25

Related Resources