Compare the login response with the next request
In the browser's network tab, open the response that ends the login and look at its Set-Cookie header. Then check whether the following request to the app sends that cookie, and compare Secure, Domain, Path and any __Host- prefix with the public URL.
Docs: developer.mozilla.org →
Log the scheme and host the app sees
Add this to a handler on the failing route and request it through nginx. If protocol is http or hostname is a container name, the app is not receiving the public values.
console.log(req.protocol, req.hostname);
Docs: expressjs.com →
Search the nginx configuration and logs for limit_req
Find any limit_req rule that applies to the login or callback location, and check the nginx logs for refusals from it. If the rule applies, scope it away from those paths or give it a burst size, then retest the loop on its own.
Docs: nginx.org →
Forward the public host and scheme from nginx
Set the headers in the location that has proxy_pass. A proxy_set_header at that level replaces the ones inherited from the server block, so repeat every header you need there. Use your own public host name.
proxy_set_header Host app.example.com;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-Host app.example.com;
Docs: nginx.org →
Tell the app to trust the proxy
In Express, the trust proxy setting exposes the information the reverse proxy provides, such as the forwarded protocol and host. The docs say the setting has to match how your proxy operates, and they accept an IP address, a subnet or a list; this example names the address nginx connects from.
app.set('trust proxy', '172.18.0.2'); // the address nginx connects from
Docs: expressjs.com →
Set the trust-host variable if the app uses Auth.js
Auth.js behind a reverse proxy needs to be told to trust the X-Forwarded-Host header. Set the variable in the container's environment and restart it.
AUTH_TRUST_HOST=true
Docs: authjs.dev →
Rewrite internal names in cookies and redirects
If the app still emits an internal Domain or Location that you cannot change in its code, rewrite them in nginx. proxy_cookie_domain changes the domain attribute of Set-Cookie, and proxy_redirect changes Location.
proxy_cookie_domain localhost example.org;
proxy_redirect http://localhost:8000/ https://example.org/;
Docs: nginx.org →