Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

How to Run a Node.js App Behind OpenLiteSpeed

This guide shows how to make OpenLiteSpeed pass web visitors to your Node.js app. It needs root access, so it is for VPS and dedicated server customers.

Domains and DNS2 min read17 steps10 screenshots

What are these things?

Node.js lets you run JavaScript programs on a server. OpenLiteSpeed is a fast web server program. It answers visitors who open your website.

A Node.js app listens on its own port, like 3000. A port is a numbered door on the server. Visitors use ports 80 and 443. So we set OpenLiteSpeed as a go-between. This is called a reverse proxy. It takes the visitor's request and hands it to your app.

Before you start

  • Log in to your server as root with SSH.
  • Have OpenLiteSpeed installed, with its WebAdmin console available (usually on port 7080).
  • Have your domain set up as a virtual host. A virtual host is one website entry inside OpenLiteSpeed.
    Screenshot_1
    Screenshot_2
    Screenshot_3
    Screenshot_4

Step 1: Install Node.js and start your app

  1. Check Node.js is installed:
    node -v
    This prints the version. If it says "not found", install Node.js with your system's package manager.
  2. Go to your app folder and install its needs:
    cd /var/www/myapp
    npm install
  3. Start the app on port 3000 with a process manager called PM2, which keeps it running:
    npm install -g pm2
    pm2 start app.js
    pm2 save
    Replace app.js with your own start file.
  4. Test it on the server:
    curl http://127.0.0.1:3000
    You should see your app's reply.
    Screenshot_5

Step 2: Add an external app in OpenLiteSpeed

  1. Log in to the WebAdmin console in your browser.
  2. Open Virtual Hosts and click your site.
  3. Open the External App tab and click Add.
  4. Set Type to Web Server.
    Screenshot_6
  5. Set Name to nodeapp.
  6. Set Address to 127.0.0.1:3000.
  7. Click Save.

Step 3: Add a context

  1. Open the Context tab and click Add.
  2. Set Type to Proxy.
    Screenshot_7
    Screenshot_8
  3. Set URI to /.
  4. Set Web Server to nodeapp.
  5. Click Save.
  6. Click Graceful Restart at the top.
    Screenshot_9

Open your domain in a browser. Your Node.js app should answer.

If it does not work

  • Run pm2 list to check that the app is running.
  • Check that the firewall does not block the ports you use.
  • Look at the OpenLiteSpeed error log.
    Screenshot_10
Tip: Keep port 3000 closed to the outside. Only OpenLiteSpeed should reach it. Menu names can differ a little between versions.

Quick recap

  • OpenLiteSpeed acts as a reverse proxy for your Node.js app.
  • Run the app with PM2 on a local port.
  • Add an external app with the address 127.0.0.1:3000.
  • Add a Proxy context for / and restart gracefully.