How to use Reverse Proxy in OpenLiteSpeed?

I want to deploy my nodejs application that contains backend and frontend for my application in openlitespeed.

I run both of them using pm2 autorunner and get the port that i setup earlier (For example i using port 8080). How can i use reverse proxy like nginx in openlitespeed? is there are step by step to do that?

i expect it to run in url like this localhost/downtime-app without using port

Actually i already set my index.html of my frontend to configured like php but when i refresh the page it will return page error 503, and i already add .htaccess in directory of my builded nodejs fe but it not working, so i want to use reverse proxy if it possible.

information : i use .htaccess like this

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>```

1. Configure OpenLiteSpeed:

  • Ensure OpenLiteSpeed is installed and running on your server.
  • Create a virtual host configuration file (e.g., your_app.conf) within the OpenLiteSpeed configuration directory (usually /etc/openlitespeed/conf).
  • Configure the virtual host as follows:

<VirtualHost *:80>
ServerName localhost

<Location />
    DocumentRoot /path/to/your/node.js/app/public
    SetHandler proxy
    ProxyPass http://127.0.0.1:8080/
    ProxyPassReverse http://127.0.0.1:8080/
</Location>
  • Replace /path/to/your/node.js/app/public with the actual path to your Node.js application’s public directory.
  • Adjust the port (8080) if your Node.js application is listening on a different port.
  • Restart OpenLiteSpeed for the changes to take effect.

2. Configure Nginx as a Reverse Proxy:

  • Install Nginx on your server if it’s not already installed.
  • Create a Nginx configuration file (e.g., your_app.conf) within the Nginx configuration directory (usually /etc/nginx/conf.d).
  • Configure Nginx as follows:
server {
    listen 80;
    server_name localhost;

    location /downtime-app {
        proxy_pass http://127.0.0.1:8080/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;   

    }
}
  • Replace localhost with the desired domain name or IP address.

[

  1. kothar.net
    ](Plex, SSL and Nginx — Kothar Labs)


kothar.net

  • Adjust the port (80) if you want to use a different port for Nginx.
  • Restart Nginx for the changes to take effect.

3. Access Your Application:

  • Open your web browser and navigate to http://localhost/downtime-app. Your Node.js application should now be accessible without using the port number.

Explanation:

  • OpenLiteSpeed acts as a web server, handling incoming requests and passing them to the Node.js application running on port 8080.
  • Nginx acts as a reverse proxy, intercepting requests for the downtime-app path and forwarding them to OpenLiteSpeed.
  • The .htaccess file in your Node.js application’s public directory is not required when using Nginx as a reverse proxy.

By following these steps, you should be able to successfully deploy your Node.js application using OpenLiteSpeed and Nginx as a reverse proxy, allowing you to access your application without using the port number.