Open source

openlitespeed-node-deploy

Zero-downtime deploys, Next.js header fixes and Cloudflare IP gating for Node apps behind OpenLiteSpeed and CyberPanel. Everything in it broke in production at least once.

Technologies Used:

OpenLiteSpeedCyberPanelNode.jsCloudflareBash

Why it exists

One OpenLiteSpeed vhost on my server serves a static Astro site plus half a dozen Node apps on sub-paths (Next.js, Express, MCP servers), all behind Cloudflare. The documentation for that setup is thin, so every problem in this repo was debugged on a live site first.

What is in it

Deploys without downtime. Astro, Vite and Next export delete their output directory before they build. If the web server serves that directory, every page is a 404 for the length of the build: 30 to 60 seconds here, and a visitor hit it. Building into a second directory and swapping with two mv calls still left a gap: under load I measured one 404 in 117 requests. Linux can exchange two paths in a single syscall, renameat2 with RENAME_EXCHANGE, and that is what the deploy script uses. This site deploys that way.

Next.js Server Actions returning 500. Behind Cloudflare and OpenLiteSpeed some headers reach the app twice, Origin among them. Node joins duplicates with a comma, Next passes the result to new URL(), and every server action dies with TypeError: Invalid URL while the pages themselves render fine. A small custom server collapses those headers before Next sees them.

IP-gating a path behind Cloudflare. The web server only ever sees Cloudflare’s addresses, and a header with the real IP can be forged unless you only trust it from Cloudflare’s ranges. The repo has the OpenLiteSpeed config and a script that keeps the Cloudflare allowlist current.

The rest is the smaller stuff: environment variables set somewhere you did not look, a node app bound to the wrong host because of HOSTNAME, ModSecurity rules that 403 webhooks and JSON-RPC.

MIT licensed. If you run Node behind CyberPanel, start with the table at the top of the README.

Key Features

  • Atomic static deploys with renameat2(RENAME_EXCHANGE), no 404 window
  • Fix for Next.js Server Actions failing with HTTP 500 behind Cloudflare + OpenLiteSpeed
  • Config for a Node app on a sub-path of an existing site
  • Restricting a path to your own IP when every request comes from Cloudflare
  • Notes on environment traps and ModSecurity blocking JSON APIs

Related Projects

Do you like this project?

Let's discuss how we can create a similar solution for your business.

Get Your Free Consultation

Or call me directly: +359 896 86 3508