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

**URL:** <https://community.auth0.com/t/got-502-bad-gateway-on-login-callback-when-using-nginx-reverse-proxy/116896>\
**Category:** Get Help\
**Tags:** oidc, protocols\
**Created:** [September 21, 2023, 11:25pm UTC](https://community.auth0.com/t/got-502-bad-gateway-on-login-callback-when-using-nginx-reverse-proxy/116896 "2023-09-21T23:25:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.samorokov](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@michael.samorokov](https://community.auth0.com/u/michael.samorokov)\
**Post date:** [September 21, 2023, 11:25pm UTC](https://community.auth0.com/t/got-502-bad-gateway-on-login-callback-when-using-nginx-reverse-proxy/116896/1 "2023-09-21T23:25:30Z")

</div>

hello!

I’m trying to integrate [ASP.NET](http://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](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.

---

<div class="post-metadata">

**Author:** ![michael.samorokov](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/User_font_awesome.svg/768px-User_font_awesome.svg.png) [@michael.samorokov](https://community.auth0.com/u/michael.samorokov)\
**Post date:** [September 21, 2023, 11:48pm UTC](https://community.auth0.com/t/got-502-bad-gateway-on-login-callback-when-using-nginx-reverse-proxy/116896/2 "2023-09-21T23:48:05Z")

</div>

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: 192.168.168.1, server: my.hostname, request: "POST /callback HTTP/2.0", upstream: "https://192.168.168.135:7176/callback", host: "my.hostname", referrer: "https://my-domain.us.auth0.com/"`

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

```auto
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 🙂

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [September 23, 2023, 7:25am UTC](https://community.auth0.com/t/got-502-bad-gateway-on-login-callback-when-using-nginx-reverse-proxy/116896/3 "2023-09-23T07:25:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [October 7, 2023, 7:25am UTC](https://community.auth0.com/t/got-502-bad-gateway-on-login-callback-when-using-nginx-reverse-proxy/116896/4 "2023-10-07T07:25:41Z")

</div>

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