
The home page loads, static files work, but login returns 502. If a request succeeds when one proxy layer is bypassed, inspect the login response as well as the application. Multiple Set-Cookie fields, long redirect URLs, or repeatedly appended headers can exceed a limit along the delivery path.
A 502 does not prove that headers are too large. Identify the layer that generated the error and confirm the cause in its logs. Oversized request cookies and oversized response Set-Cookie fields travel in opposite directions; raising request-header limits may have no effect on this failure.
Identify the proxy generating the 502
Record the timestamp with time zone, path, status, CDN request ID, and logs from each layer. The chain may include a CDN, load balancer, Nginx, and application server. The client-visible 502 can originate at the CDN or be passed through from an origin proxy.
If the origin proxy reports an error such as upstream sent too big header, investigate that layer's upstream response-header limits. If logs instead show a reset, TLS failure, or timeout, follow that evidence before changing buffers.
Failures limited to login, SSO callbacks, or session refreshes are a reason to inspect concentrated cookie-setting and redirect behavior. A successful home page does not establish that the login route uses the same backend or rules.
Compare successful and failing response headers
Reproduce with an isolated test account or in staging. Cookies, authorization codes, session identifiers, and redirect parameters can contain secrets. Keep raw headers in controlled storage; share field names, counts, and lengths with values redacted.
Measure the number and length of Set-Cookie fields. Inspect Location, Content-Security-Policy, and custom tracing fields too. Common changes worth investigating include:
Session data or permission lists embedded directly in cookies.
Multiple components repeatedly setting cookies or appending headers.
Nested callback URLs creating excessively long redirect parameters.
A release adding tracing, security-policy, or identity-provider fields.
A browser accepting a response does not establish that every intermediate proxy accepts it. Individual field limits and total header-list limits may also differ. Check the documented limits and effective configuration at each boundary.
Use a public test path to check the measurement method
This Linux shell example reads a public test path; it does not log in. It illustrates saving headers from GET. Capture the actual login response through an authorized test flow rather than substituting an unauthenticated GET.
umask 077 curl -sS --max-time 15 \ -D response.headers -o /dev/null \ 'https://www.example.com/test/public' wc -c response.headers
The saved byte count is useful for comparison, but it is not necessarily the exact accounting used by a proxy handling HTTP/2 or HTTP/3. The file may contain multiple header blocks, including informational responses. Following redirects can add headers from several exchanges, so do not treat the whole file as one upstream response.
HEAD omits the body and may exercise different application logic. A curl -I probe alone does not validate a login response. Match the actual request conditions and method without printing real Set-Cookie values to shared terminal logs.
Distinguish HTTP-proxy buffers from FastCGI buffers
NGINX documents proxy_buffer_size as the buffer for the first part of an upstream response, which usually contains its headers. If that first part exceeds the buffer, the response is considered invalid. proxy_buffers addresses response buffering more broadly; it is not an interchangeable setting.
For a FastCGI upstream such as PHP-FPM, inspect fastcgi_buffer_size and the corresponding FastCGI directives. Changing proxy_buffer_size may not affect that route. A CDN, hosted load balancer, or application server can impose an independent limit that an origin Nginx setting cannot raise.
Confirm the active location, upstream protocol, and loaded configuration before editing. Avoid copying a large buffer configuration across the whole site. Related directives can have configuration constraints, and memory implications need to be assessed against concurrency.
Reduce unnecessary header growth first
If session payloads have become excessive, evaluate a short session identifier with server-side state, using the application's expiry and revocation requirements. Remove genuinely duplicated fields, repair nested redirect URLs, and establish which layer owns each security or tracing header.
Do not delete authentication cookies, security policy, or identity checks merely to obtain 200. Multiple Set-Cookie fields must not be casually combined into a comma-separated field; cookie syntax and processing require separate care.
If reasonable headers still exceed a self-managed proxy limit, evaluate a scoped buffer change. Save the original configuration, run nginx -t, and deploy gradually through the normal reload process. Verify login, logout, session renewal, and memory under concurrency. Restore the original configuration if behavior regresses.
Validate session behavior, not just the status code
Use a test account to cover login, SSO callbacks, session refresh, and logout. Check that expected cookies are set with the correct Domain and Path and retain required security attributes. Confirm that sessions are not duplicated and redirects do not loop.
Test both a clean client and an existing session. Correlate proxy errors, application outcomes, and the 502 rate. Authentication responses need suitable private or no-store cache controls; putting login responses in a shared cache is not a fix for an upstream failure.
Keep a redacted baseline of header counts and lengths for later releases. If 502 persists while headers are within each layer's limits, continue investigating connections, response validity, and application errors rather than increasing buffers indefinitely.
References
The command is a public test-path example and has not been executed in your production environment. Verify response-header limits for CDNs and hosted load balancers against their current documentation and deployed configuration.