Do you want to create a NodeJS application in OpenLiteSpeed(OLS) RunCloud server ? I'm going to show you how to do it using the example. If you have ever created an Apache based NodeJS application, but want to use OLS for your next project, then this post is for you. Let's examine how a Node.js application can be executed on an OpenLiteSpeed server (OLS) while a RunCloud server is being used.
For RunCloud Nginx server refer : Quick Start Guide: How To Install Node js Project In Runcloud (linuxtutorialz.co.uk)
Step 1
First, we need to create a empty web application. Refer hereNow we need to use a terminal to connect to the server (or SFTP if it's ready for upload)
I used a terminal to access the server as the owner of a web application (in my case runcloud).
This sample application is what I'm using as my example. here. As it's a git repo, I'm cloning it as followsgit clone https://github.com/contentful/the-example-app.nodejs.git .
Before running the aforementioned command, confirm that you are at the web application root directory.
Once the content is available in backend, run the command
npm install
The application can be started by running below command.
npm run start:dev
If we open another terminal, then we can test this via
curl http://localhost:3000
The content of our website should appear in the terminal.However, the web application would stop as well once we close the terminal, therefore we added it via supervisor (you can try pm2 as well).
Step 2
Now, though, it will only function in a browser if we access your domain using the url http:domain.com:3000. However, we employ the concept of a proxy since we want this to appear as domain.com without any server firewall ports being open. Head over to your web application in RunCloud dashboard and find the 'litespeed config' option in left side.
In right side, you can find your configuration as below
extprocessor nodejs {
type lsapi
address UDS://tmp/lshttpd/nodejs.sock
maxConns 35
env PHP_LSAPI_MAX_REQUESTS=5000
env PHP_LSAPI_CHILDREN=35
................
Please note, here nodejs is my web application name. However, inorder to do the proxy, we need to change the config to following.
extprocessor WEBapp_name {
type proxy
address http://localhost:8182
.......................
As you may noticed, we just need to update the value of 'type' and 'address'. The type change will notify it's a proxy and address field with our port will redirect access to this web application to our nodejs application. Also, we need to add following line to our .htaccess
RewriteRule ^(.*)$ http://WEBAPP_NAME/$1 [P]
Please make sure to replace WEBAPP-NAME with your web application name(in my case nodejs).
Now, your website should be loading fine.
Hello. Excellent tutorial. I was able to get this working for an http reverse proxy, but how can we configure web sockets proxy to work in this environment? The app I am trying to install on runcloud's openlitespeed is uptime-kuma. It's opening, but web sockets are not connecting.
ReplyDeleteWhat's the error bro?
ReplyDelete