A cloud-based identity and access management service for securing user authentication and resource access
The 502 Bad Gateway indicates that Nginx can’t successfully proxy the /signin-oidc callback to the ASP.NET Core app on http://127.0.0.1:5000, even though Microsoft Entra ID has issued and validated the token.
From the provided configuration and logs, the relevant points are:
- Nginx is correctly configured as a reverse proxy to
http://127.0.0.1:5000on port 443, including forwardingHost,X-Forwarded-Proto, and other headers, which matches the documented pattern for ASP.NET Core + Nginx reverse proxy. - The ASP.NET Core app is configured to use forwarded headers via
UseForwardedHeaders()andForwardedHeadersOptions, which is required when running behind a reverse proxy. - The Microsoft Identity logs show that the token lifetime and audience are valid, and a claims identity is created, which means the OpenID Connect response is being processed inside the app.
- The 502 is a proxy error, which (per the Nginx + ASP.NET Core guidance) occurs when Nginx can’t reach or get a valid response from the backend application when forwarding the request.
Given these facts, the issue is in the communication between Nginx and the ASP.NET Core app on Linux, not in Microsoft Entra ID itself. The documented guidance for this setup highlights these checks:
- Confirm that the ASP.NET Core app is actually running and listening on
http://127.0.0.1:5000on Ubuntu (for example by runningdotnet <app_assembly.dll>directly and testingcurl http://127.0.0.1:5000from the server). - Verify that Nginx is using the correct upstream address and port (
proxy_pass http://127.0.0.1:5000;) and that there is no firewall or SELinux rule blocking local traffic. - After any change to Nginx configuration, run
sudo nginx -tto validate the configuration and thensudo nginx -s reloadto apply it. - If the app runs locally but doesn’t respond through Nginx, check Nginx error logs for 502-related details and adjust proxy-related settings (for example, header and buffer limits) only if needed. The documentation notes that default proxy buffer limits can cause issues with long headers (such as those used by Microsoft Entra ID), and that increasing
proxy_buffer_size,proxy_buffers,proxy_busy_buffers_size, orlarge_client_header_buffersmay be required in such scenarios, but only when necessary due to DoS risk.
In summary, the Microsoft Entra ID token is valid and processed, and the 502 is due to Nginx not being able to successfully forward or receive the response from the ASP.NET Core app on 127.0.0.1:5000. The next steps are to verify the app is listening on that endpoint on Ubuntu, confirm Nginx can reach it, validate and reload the Nginx configuration, and only then consider adjusting proxy buffer limits if long headers are involved.
References: