nextjs - 💡(How to fix) Fix 502: Bad Gateway [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#83817Fetched 2026-04-08 02:21:24
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
closed ×1commented ×1labeled ×1locked ×1

Error Message

I'm facing the same problem. I'm using remote CDN images and have set remotePatterns in next.config.js, but I get the same error with some images. Also, 502 is random, sometimes image is served, sometimes not.

RAW_BUFFERClick to expand / collapse

I'm facing the same problem. I'm using remote CDN images and have set remotePatterns in next.config.js, but I get the same error with some images. Also, 502 is random, sometimes image is served, sometimes not. Tried -> -installing sharp. -reduced size. but nothing fixes the issue. Also I found out that my url contains %20 and this changes to %2520 this might be the issue or not I am not sure...?

extent analysis

TL;DR

The issue with randomly failing image serving over a CDN might be related to URL encoding, specifically the conversion of %20 to %2520, which could be causing inconsistencies in image requests.

Guidance

  • Verify if the issue persists when using a URL without spaces or special characters to isolate the encoding problem.
  • Check the CDN configuration to ensure it correctly handles URL encoding, particularly for spaces represented as %20.
  • Test if the problem occurs with images hosted locally or only with those served from the remote CDN to narrow down the cause.
  • Consider encoding the URL differently or using a library to handle URL encoding to prevent the %20 to %2520 conversion.

Example

No specific code example can be provided without more context, but ensuring proper URL encoding might involve using a function like encodeURIComponent() in JavaScript to handle special characters.

Notes

The randomness of the 502 error and the image sometimes being served suggests an intermittent issue, possibly related to how the CDN handles requests or the specific images being requested. The conversion of %20 to %2520 could be a red herring or a symptom of a larger encoding issue.

Recommendation

Apply a workaround by ensuring consistent URL encoding for images, possibly by manually encoding URLs or using a library to handle this, as the root cause seems related to how URLs are interpreted by the CDN or the application.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING