Skip to content

Set up OpenLiteSpeed as a Reverse Proxy for a Node.js App

In this guide, we will set up OpenLiteSpeed (OLS) as a reverse proxy for a Node.js application. In our example, we will use the Docker compose method. If you already have an app started as a container, then you can skip right to Set up OpenLiteSpeed as a Proxy.

Set up Node.js

Download the OLS Docker stack and change to the ols-docker-env directory:

git clone; cd ols-docker-env

Follow the official Docker instructions to create a simple Node.js application.

The folder name will be node-docker, and the structure will look like this:

├── acme
├── bin
├── data
│   └── db
├── docker-compose.yml
├── logs
├── lsws
│   ├── admin-conf
│   └── conf
└── node-docker
    ├── Dockerfile
    ├── node_modules
    ├── package.json
    └── server.js

Test the application:

curl --request POST \
  --url http://localhost:8000/test \
  --header 'content-type: application/json' \
  --data '{"msg": "testing" }'

The output should look like this:


Edit docker-compose.yml and include the following content:

version: '3'
    image: litespeedtech/openlitespeed:${OLS_VERSION}-${PHP_VERSION}
      - .env
        - ./lsws/conf:/usr/local/lsws/conf
        - ./lsws/admin-conf:/usr/local/lsws/admin/conf
        - ./bin/container:/usr/local/bin
        - ./sites:/var/www/vhosts/
        - ./acme:/root/
        - ./logs:/usr/local/lsws/logs/
      - 80:80
      - 443:443
      - 443:443/udp
      - 7080:7080
    restart: always
      TZ: ${TimeZone}
    network_mode: "host"

    image: nodejs
    build: node-docker/.
      - NODE_ENV=production
      - 8000:8000

Set up OpenLiteSpeed as a Proxy

Using the official OLS as Reverse Proxy guide, we can set up OLS by creating an external app, and adding rewrite rules.

Create a Web Server External Application

Log in to the OLS WebAdmin Console. To set up a server-level external application, navigate to Server Configuration > External App > Add > Type. Give it the following values:

  • Name = nodejs
  • Address = localhost:8000
  • Max Connections = 100
  • Initial Request Timeout = 60
  • Retry Timeout = 0
  • Response Buffering = No

Add Proxying Rewrite Rules

Navigate to Virtual Host Templates > docker > Rewrite > Rewrite Rules > Add and add a set of rewrite rules, like these:

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ HTTP://nodejs/$1 [P,L,]
RewriteRule ^(.*)$ HTTPS://nodejs/$1 [P,L,]
Replace the URL with the address of your OLS server.


Use curl command to check the server is served by LiteSpeed.

curl -I

The output should look like this:

HTTP/2 200
x-powered-by: Express
access-control-allow-origin: *
content-type: application/json; charset=utf-8
etag: W/"1b3-MxQbaP1S3gmyG6akl7lrj8F0CMY"
server: LiteSpeed
alt-svc: h3=":443"; ma=2592000, h3-29=":443"; ma=2592000, h3-Q050=":443"; ma=2592000, h3-Q046=":443"; ma=2592000, h3-Q043=":443"; ma=2592000, quic=":443"; ma=2592000; v="43,46"

Last update: October 16, 2023