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.
 
DA is falling behind. Wasnt there an announcement about another implementation upcoming?
I'm currently having a look at OpenResty. Word on the street is it's faster and possibly better than NGINX, while staying compatible with NGINX. I'll be having another look at it later tonight after work.
 
Yep, I still find the workaround on nodejs app for my customer too.

This is just my idea, create systemd service and run
"/bin/jailshell -c 'pm2-runtime ${HOME}/pm2.econsystem.config.js".


Like
Code:
systemctl start "[email protected]"
systemctl start "[email protected]"
Is this safe enought ?

I'm using pm2 for my own App and working well, but I don't know when give some one to running this is secure enought or not.
 
Back
Top