Skip to content

Conversation

@TheDanniCraft
Copy link

@TheDanniCraft TheDanniCraft commented Dec 21, 2025

Description

Fixes an issue where rewrites acting as proxies can return 500 Internal Server Error when running Next.js behind a reverse proxy in standalone production builds.

The request is correctly received by Next.js, proxied upstream, and the upstream responds with 200, but the client still receives a 500 response when response compression is enabled.

I already documented this behavior in PR #87244. That PR aims to fix the same 500 error when using rewrites as proxies, but through a different approach.
The issue still reproduced in this setup.

This PR fixes the problem by explicitly removing the Accept-Encoding header on proxied requests, preventing double compression when running behind a reverse proxy.

#87244 (comment)

Research and Findings

During debugging, the following was observed:

  • The request consistently reaches the Next.js server and executes proxyRequest
  • The upstream responds successfully with status 200
  • The response fully completes inside Next.js
  • When running behind Traefik with compression enabled, clients receive 500
  • Removing Accept-Encoding or forcing identity resolves the issue

This strongly indicates a double compression or content encoding mismatch when multiple reverse proxies are involved.

Changes

  • Remove the Accept-Encoding header for proxied requests to prevent double compression
  • Keep proxy behavior otherwise unchanged

Fixes

Fixes #87071

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Next.js 16: rewrite/proxy no longer works in production (500), but works in dev

2 participants