Skip to content

Node.js

The OpenLiteSpeed Node.js One-Click app automatically installs performance web server OpenLiteSpeed, and Node.js. This image tends to be more than 4 times faster than Node.js with Nginx! OpenLiteSpeed features easy setup for SSL and RewriteRules. OLS is flexible and also supports Python and Ruby apps, as well as CMSs like WordPress.

Quick Start

Step 1.

Use the "OpenLiteSpeed Node.js Marketplace Image" to create a ECS with any plan you want.

Step 2.

An interactive script that runs will prompt you for your domain or subdomain:

Please input a valid domain:
Please verify it is correct. [y/N]

Enter your root domain only. The system will automatically add the www subdomain as well.

Note

You can press CTRL+C and continue to SSH, but the prompt will open again the next time you log in. It will continue to do so until you finish the whole setup.

If your domain is already pointed to this server, you will have the option of automatically applying Let's Encrypt SSL. Enter y and your email address to complete the process:

Do you wish to issue a Let's encrypt certificate for this domain? [y/N]
Please enter your E-mail:
Please verify it is correct: [y/N]

Once finished, you should see Certificate has been successfully installed...

You can force HTTPS rules to be applied:

Do you wish to force HTTPS rewrite rule for this domain? [y/N]

Complete the process by pressing Y:

Do you wish to update the system which include the web server? [Y/n]

You should not be prompted to initiate this setup again.

Step 3.

Visit the default script by entering http://Server_IP on your browser and you should see Hello World from OpenLiteSpeed Node.js.

Start editing the Node.js file here

vim /usr/local/lsws/Example/html/node/app.js

Update system software.

sudo apt-get update && sudo apt-get upgrade -y

Your system is installed and ready to use!

Components

The OpenLiteSpeed Node.js 1-Click Droplet installs several packages and performs other actions on your system.

Package Installation

Component Version
Linux Ubuntu 18.04.1
OpenLiteSpeed Latest from LiteSpeedtech Repo
Node.js Latest from APT
NPM Latest from APT
Certbot Latest from Certbot’s PPA

Other Actions

  • Enables the UFW firewall to allow only SSH (port 22), HTTP (port 80) and HTTPS (port 443) access.

Benchmark Comparison

Use the following command to test from a 4-CPU plan server(ab) to a 4-CPU plan server(DOMAIN)

ab -n 100000 -k -H "Accept-Encoding: gzip,deflate" -c 100 http://DOMAIN/

Requests per Second (The larger the number, the better)

Nginx+PM2 Openlitespeed
2600 12000

How to Access the Installed Software

From a terminal on your local computer, connect to the server as root, like so:

ssh root@192.0.2.0

Be sure to substitute the server’s public IP address for 192.0.2.0.

Web Server Control Panel Access

Get the WebAdmin admin password:

cat .litespeed_password

Visit https://use_your_droplet_ip:7080 to access WebAdmin in a browser.

!wpapp

By default, WebAdmin uses port 7080. To allow access to 7080 from your IP(e.g. 192.0.2.0):

ufw allow from 192.0.2.0 to any port 7080
You can also allow all IPs access to port 7080:
ufw allow 7080
We suggest turning this port off once you've finished setup:
ufw delete allow 7080

Optional Setup

Enable HTTPS

Setting up an SSL certificate enables HTTPS on the web server, which secures the traffic between the server and the clients connecting to it. Certbot is a free and automated way to set up SSL certificates on a server.

Step 1. Register Domain

To use Certbot, you’ll need a registered domain name and DNS records:

  • An A record from the domain (e.g., example.com) to the server’s IP address

  • An A record from the domain prefaced with www (e.g., www.example.com) to the server’s IP address.

Step 2. Add Domain to Listener

Navigate to OpenLiteSpeed WebAdmin Console > Listeners, and add Your Domain to HTTP/HTTPS. !listener 1

Step 3. Certbot

Once the DNS records are set up, you can generate the SSL certificate. Be sure to substitute the correct domain name in the following command:

certbot certonly --webroot -w /var/www/html/ -d example.com -d www.example.com
If certificate verification is a success, you should find your certificate files stored in /etc/letsencrypt/

Step 4. Set SSL for HTTPS

!wpapp 7

Navigate to OpenLiteSpeed WebAdmin Console > Listeners > SSL, and edit the following three items:

  • Private Key File = /etc/letsencrypt/live/example.com/privkey.pem
  • Certificate File = /etc/letsencrypt/live/example.com/fullchain.pem
  • Chained Certificate = Yes

Save and perform a Graceful Restart.

Now your server should support TLS1.1, TLS 1.2, and TLS 1.3.

Step 5. Redirect HTTP to HTTPS

!wpapp 8

HTTPS traffic on port 443 is already allowed through the firewall. After you set up HTTPS, you can optionally rewrite all HTTP traffic to HTTPS.

Add the following rules to OpenLiteSpeed WebAdmin Console > Virtual Hosts > Rewrite > Rewrite Rules

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]

Method for Uploading Files

You can serve files from the web server by adding them to the web root using SFTP or other tools.

Frequently Asked Questions

How do I Reset my Web Server WebAdmin Password?

If you forget your password, you may run the following command to reset it:

/usr/local/lsws/admin/misc/admpass.sh

It will ask for the WebAdmin username, which should be admin. Then, enter your new password.

How do I Create Additional Virtual Hosts?

How do I Create Additional Apps by Context?

How do I Change the Node.js Startup File?

If you want to change the default startup file name from app.js to node.js, just update the Context and set Startup File = node.js.

How do I upgrade Node.js to latest stable version

Install Node.js by using n module

sudo n stable
     install : node-vX.X.X
       mkdir : /usr/local/n/versions/node/X.X.X
       fetch : https://nodejs.org/dist/vX.X.X/node-vX.X.X-linux-x64.tar.gz
################################################################################## 100.0%
   installed : vX.X.X
Setup binary link
ln -sf /usr/local/n/versions/node/X.X.X/bin/node /usr/bin/node

How do I use an Express app on this image?

Setting up an Express app is easy. First, install the Express.js module:

npm install express --save

Then, change your startup file (app.js) from a Node.js program to an Express JS program:

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World from OpenLitespeed Express JS!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

Finally, restart OpenLiteSpeed:

service lsws restart

And you're done!