Got "502 Bad Gateway" on login callback when using NGINX reverse proxy


I’m trying to integrate ASP.NET Core application with Auth0.
I’m using Auth0.AspNetCore.Authentication NuGet package following tutorial documentation by @andrea.chiarelli .
It works fine when I’m trying locally using https://localhost URL.

When I add a Nginx reverse proxy in front of the application several things happen.

  1. If I try to terminate https on NGINX (application runs as http) the redirect URL constructed by LoginAuthenticationPropertiesBuilder is http.
    This can be work around by modifying the URL in props or running the service itself with https.

  2. After I login I get “502 Bad Gateway” from Nginx.
    I tried adding ForwardedHeaders on startup, but it didn’t help.

Did someone else face this issue? It should be common as many applications run behind Nginx reverse proxy in production.

Ok, I’ve figured it out.
Here is what I found in Nginx logs:

2023/09/21 23:35:10 [error] 2659942#2659942: *522258 upstream sent too big header while reading response header from upstream, client:, server: my.hostname, request: "POST /callback HTTP/2.0", upstream: "", host: "my.hostname", referrer: ""

So it works fine after adding this buffer config to Nginx:

server {
 proxy_busy_buffers_size   512k;
 proxy_buffers   4 512k;
 proxy_buffer_size   256k;
 # rest of the nginx config below #

Don’t forget to bump your Nginx memory :slight_smile:

1 Like

Glad to hear you were able to solve it, and thanks for sharing the solution :pray:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.