Node App Does Not Load

#1
I have followed the instructions to create a simple nodejs app on OLS https://openlitespeed.org/kb/running-node-js-apps-with-openlitespeed/
I already have a letsencript SSL certificate installed and have a website running from this server at https://petersmusic.tk

I have two questions about this. One is that the tutorial says this:

This example assumes you are using the default document root + URI: /node/

But then in the configuration it says to put the location as /usr/local/lsws/Example/node/ (replacing Example with my directory name, of course).
I thought that the document root was the html folder, from where the server serves files if you type example.com in the address bar by itself. Is this a mistake in the tutorial? Should this say something else? I am assuming that the app.js file should go in /usr/local/lsws/Example/node/ and that that is also the same path that goes in the Location box.

The other question is this:

The instructions say to go to http://Server_IP : port/node/ to make the app.js script run. I have replaced the IP address with my domain name: petersmusic.tk:3000/node
but the server stalls and then the browser says "Unable to connect." Using my IP as the tutorial suggests has the same result.

Given that I already have a domain and the https set up, should I use a different URL from the tutorial? I have tried changing http to https in the app.js script, but that does not help.
 
Last edited:
#3
Thanks for the reply.

1. I am not sure why I am getting a 404 error. I have an app.js file in the /usr/local/lsws/petersmusic/node directory, and I have verified that there is a node executable in /home/homedirectory/.nvm/versions/node/v18.13.0/bin/node .




2. Do I need to do something different from the tutorial in app.js if I have SSL? I have seen some node examples for SSL that do this:

console.error("Test!!!");
const https = require('https'),
fs = require('fs');

const options = {
key: fs.readFileSync("/etc/letsencrypt/live/directoryname/privkey.pem"), // include the SSL files
cert: fs.readFileSync("/etc/letsencrypt/live/directoryname/fullchain.pem")
};

const hostname = '127.0.0.1';
const port = 443;

const server = https.createServer(options, (req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');

res.end('Hello World form node js app.js\n');
});

server.listen(port, hostname, () => {
console.log(`Server running form root at http://${hostname}:${port}/`);

When using this code in app.js, I got the following output from Stderr.log:

2023-01-17 19:31:38.742 [STDERR] Test!!!
2023-01-17 19:31:39.100 [STDERR] node:events:491
throw er; // Unhandled 'error' event
^

Error: listen EACCES: permission denied 127.0.0.1:443
at Server.setupListenHandle [as _listen2] (node:net:1716:21)
at listenInCluster (node:net:1781:12)
at doListen (node:net:1930:7)
at process.processTicksAndRejections (node:internal/process/task_queues:83:21)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1760:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'EACCES',
errno: -13,
syscall: 'listen',
address: '127.0.0.1',
port: 443
}


afaik the server has access to these .pem files because I gave them group access.



If I do it the non-https way, I get no errors from stderror, but I still get a 404 from the browser:

console.error("Test!!!");

// const https = require('https'),
const https = require('http'),
fs = require('fs');

// const options = {
// key: fs.readFileSync("/etc/letsencrypt/live/directory/privkey.pem"),
// cert: fs.readFileSync("/etc/letsencrypt/live/directory/fullchain.pem")
// };

const hostname = '127.0.0.1';
const port = 443;

// const server = https.createServer(options, (req, res) => {
const server = https.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');

res.end('Hello World form node js app.js\n');
});

server.listen(port, hostname, () => {
console.log(`Server running form root at http://${hostname}:${port}/`);


});

Stderr.log:
2023-01-17 19:34:35.861 [STDERR] Test!!!



Notice that the console.error message works, so node must be running.
Why am I getting a 404? What is missing?

3. You say that it's not a proxy. I am not sure I know the difference between what I am doing and proxying. The tutorial says, "OpenLiteSpeed Web Server can be configured to proxy traffic to Node.js so that users can run Node.js applications (like Ghost) on their sites." What does it mean to proxy?
 

Attachments

Top