Next.js (App Router + API routes) failing on Nginx Unit – appendHeader error

Cartitarul

Verified User
Joined
Jul 19, 2023
Messages
38
Hello,
I’m trying to run a Next.js application (App Router) on a server using DirectAdmin + Nginx Unit, and I’m running into what looks like a compatibility issue.

My setup​

  • DirectAdmin with Nginx Unit
  • Node.js (tested Node 24, also tried downgrading)
  • Next.js (App Router, using /app)
  • The app includes API routes (e.g. /app/api/projects, /app/api/admin/session)
  • Previously worked locally using npm run dev and npm run start

What I tried​

  • Created a Unit Node application with a proper server.js
  • Installed dependencies and ran npm run build
  • Confirmed .next/ build output exists
  • Ensured Unit working directory is correct
  • Cleaned up workspace/lockfile issues
  • Tried static export (output: "export") but it fails due to API routes (expected)

The error​


When running the app via Unit, it crashes during SSR with:
TypeError: b.appendHeader is not a function
This happens consistently inside .next/server/chunks/ssr/....

From debugging, it appears that Next.js expects a standard Node http.ServerResponse, but Unit’s Node HTTP adapter provides a response object that doesn’t fully match Node’s API, causing Next SSR to fail.


My question​


Is modern Next.js (App Router + SSR + API routes) officially supported on Nginx Unit?
If not:
  • Is there a recommended workaround?
  • Or is the expected approach to run Next.js outside Unit (Node + pm2) and reverse-proxy with nginx?
I want to make sure I’m not fighting a known limitation.

Thanks in advance for any clarification.
 
Thank you for the response, any alternatives plugins or ideeas on how I can host this type of applications ?
 
Back
Top