July 12, 2022 . 2 MIN READ
Node.js typically runs as a standalone web server. However, OpenLiteSpeed can be configured to proxy requests to a Node.js application, allowing you to run apps (such as Ghost) seamlessly on your server.
This guide explains how to run Node.js applications with OpenLiteSpeed. It assumes that Node.js is already installed and your virtual hosts are properly configured.
OpenLiteSpeed version 1.4.41 or higher
Node.js installed
Virtual host already set up
If Node.js is not installed yet, install it using:
CentOS:
Ubuntu:
In this example, we use the default URI: /node/
Navigate to:
Web Admin → Virtual Hosts → Context → Add
Set the following values:
Type: App Server
URI: /node/
Location: /usr/local/lsws/Example/node/
Binary Path: /usr/bin/node
Application Type: node
Create a node directory inside your document root.
Create a file named app.js with the following content:
const hostname = ‘127.0.0.1’;
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader(‘Content-Type’, ‘text/plain’);
res.end(‘Hello World from Node.js app\n‘);
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Open your browser and visit:
You should see:
If Node.js is installed in a different location, update:
Binary Path: /usr/node (or your custom path)
To use a different startup file (e.g., node.js instead of app.js):
Set Startup File: node.js in the context configuration
OpenLiteSpeed acts as a proxy between users and your Node.js app
Ensure correct file permissions and paths
Restart OpenLiteSpeed after making configuration changes
Reference:
https://openlitespeed.org/kb/running-node-js-apps-with-openlitespeed/