How to Run Multiple Inertia SSR Servers on a Shared Server

How to Run Multiple Inertia SSR Servers on a Shared Server

Introduction

When deploying multiple Inertia.js applications with Server-Side Rendering (SSR) on a shared server, you might encounter a critical issue that can bring your server to its knees. In my case, I discovered that Supervisord wasn't properly starting multiple SSR servers, leading to 100% CPU usage and system instability.

The root cause? All Inertia SSR servers were attempting to use the same default port (13714), creating an infinite loop of port conflicts. In this guide, I'll show you how to resolve this issue and properly configure multiple Inertia SSR servers on a single machine.


Prerequisites

For context, here's my setup:

  • A Hetzner Cloud Server
  • Supervisord for process management
  • Laravel + Inertia.js + Vue.js stack
  • Vite for asset bundling

Understanding the Problem

In a production environment, Inertia.js recommends using a worker (like Supervisord) to manage the SSR process. This worker ensures the SSR server restarts automatically when needed, such as after deploying new changes via GitHub Actions.

However, when running multiple Inertia.js applications on the same server, we hit a roadblock: by default, every Inertia SSR server tries to use port 13714. This creates several issues:

  1. Port conflicts between applications
  2. Failed server starts
  3. CPU usage spikes to 100%
  4. Infinite restart loops

Surprisingly, the Inertia Docs doesn't address this specific scenario of running multiple SSR servers.


Solution

By default, Intertia will run on port 13714. To fix this issue, there are a couple of things we need to change.

Let’s create a couple of env variables:

# Remember default is 13714, so we need to define a
# new port number that won't conflict with the existing SSR Server
INERTIA_SSR_PORT=13715

VITE_INERTIA_SSR_PORT="${INERTIA_SSR_PORT}"

Next up, we need to publish the Inertia config file:

php artisan vendor:publish --provider "Inertia\ServiceProvider"

In your config/inertia.php file, find the ssr => 'url'.

Replace:

'url' => 'http://127.0.0.1:13714',

With this:

'url' => 'http://127.0.0.1:' . env('INERTIA_SSR_PORT', 13714),

Now, finally, we need to set the port in the ssr.js like so:

createServer(page =>
  createInertiaApp({
    // config here...
  }),
  import.meta.env.VITE_INERTIA_SSR_PORT || 13714
)

Check Its Working

So, after you have deployed, you can run a couple of commands to check everything is working. You need to SSH into your server (I’m using Linux)

You can run ss -tuln to check which apps are using the ports, or you can also check the CPU usage, if it’s not 100% usage most of the time, then we can conclude that everything is working fine


Further Learning Resources

If you're looking to deepen your understanding of Inertia.js and build modern single-page applications, I recommend checking out these comprehensive courses based on your preferred frontend framework:

For Vue.js Developers

Laravel 11 with Inertia.js and Vue 3

  • Learn to build SPAs with Laravel 11, Vue 3, and Inertia
  • Highly rated (4.7/5) with 380+ students
  • Includes practical projects and real-world implementations

For React Developers

Laravel 11 with Inertia.js and React

  • Master SPA development with Laravel 11, React, and Inertia
  • Rated 4.5/5 with 300+ satisfied students
  • Perfect for both Laravel developers learning React and React developers exploring Laravel
🔥 New Course Alert
★★★★☆4.4/5

Learn Livewire V3 from Scratch : Practical Course

Learn Livewire practically by building multiple real-world projects along the way.

30-Day Money Back
300+ Students
Limited Time
80% OFF
Enroll Now
N
Nuta Constantin S.
★★★★★

I liked it! It was very clear, made it looks simple, and I had resources for view files