NGINX Forward Auth Integration#
Tinyauth integrates with NGINX-based reverse proxies (including NGINX Proxy Manager and Swag) using NGINX's auth_request module. Because auth_request does not support native 302 redirects, Tinyauth uses a dedicated endpoint and a custom response header to work around this limitation .
The auth endpoint for NGINX is /api/auth/nginx . Requests to this endpoint are handled by the proxy controller, which recognizes nginx as a distinct proxy type and always returns non-browser responses regardless of the incoming User-Agent .
How the Auth Flow Works#
NGINX's auth_request module makes a subrequest to /api/auth/nginx. Tinyauth responds:
- Authenticated (200): Sets identity headers (
Remote-User,Remote-Name,Remote-Email,Remote-Groups,Remote-Sub) for the upstream app . - Unauthenticated (401) or Forbidden (403): Returns a JSON error and sets the
x-tinyauth-locationresponse header with the login/unauthorized URL .
NGINX is then configured to capture x-tinyauth-location and use it in an error_page directive to perform the redirect:
auth_request /tinyauth;
auth_request_set $redirection_url $upstream_http_x_tinyauth_location;
error_page 401 403 =302 $redirection_url;
The /tinyauth internal location proxies to http://tinyauth:3000/api/auth/nginx and must pass the forwarded headers (x-forwarded-host, x-forwarded-uri, x-forwarded-proto) so Tinyauth can reconstruct the original request URL . For NGINX, Tinyauth tries the AuthRequest module first, then falls back to ForwardAuth .
Key Configuration Requirements#
- Disable "Block Common Exploits" on the Tinyauth host in NGINX Proxy Manager β this feature blocks URLs in query parameters, which Tinyauth requires .
- Set
TINYAUTH_AUTH_TRUSTEDPROXIESto the NGINX instance IP so Tinyauth can trustX-Real-IP/X-Forwarded-Forheaders for IP-based ACLs . - For Docker-based NGINX setups, run NGINX in
network_mode: hostto ensure correct client IP detection .
The full NGINX Proxy Manager configuration guide, including a sample Docker Compose file, is at nginx-proxy-manager.mdx.
v5.1.x Regression Fixes#
login_for Optional (v5.1.1 β patched in v5.1.2)#
v5.1.0 added a required login_for query parameter for app redirects. This broke older NGINX setups (e.g., Swag/LinuxServer configs) that used the plain redirect path without the new x-tinyauth-location header, causing post-login redirects to fail . The fix (commit 0c1a64d) made login_for optional on the frontend: if absent but redirect_uri is present, the frontend now defaults to /continue instead of /logout . The backend still sets login_for=app by default .
Root-Domain Redirect Failure (v5.1.0β5.1.1 β fixed in v5.1.2)#
The stricter redirect validation introduced in v5.1.0 via PR #950 caused Tinyauth to reject redirects to root domains (e.g., protecting domain.com when Tinyauth is on tinyauth.domain.com). The isRedirectSafe() function's subdomain check required the redirect hostname to end with ".{cookieDomain}", but the root domain itself never satisfies that condition . Fixed in v5.1.2-beta.1; confirmed working by affected users .
TOTP + NGINX Post-Login Redirect (v5.1.0β5.1.1 β fixed in v5.1.2)#
After a successful TOTP submission, the frontend navigated to /logout instead of the original redirect_uri. This affected NGINX Proxy Manager users with 2FA enabled. Fixed in v5.1.2-beta.3 after iterative beta testing .
Source Pointers#
| Resource | Reference |
|---|---|
| NGINX Proxy Manager guide | nginx-proxy-manager.mdx |
| Proxy controller (handler, headers, auth modules) | proxy_controller.go |
useBrowserResponse() (NGINX always non-browser) | proxy_controller.go:348β361 |
determineAuthModules() (AuthRequest + ForwardAuth) | proxy_controller.go:479β490 |
login_for optional fix issue | Issue #1023 |
| Redirect regression issue | Issue #1021 |