Node.js app registered but not working correctly on Add-On domain

Operating System & Version
Cent OS 7

g_silverfox

Registered
Jun 10, 2020
4
0
1
Techvill!
cPanel Access Level
Root Administrator
Hoping somebody can help with this. To start off with I will say I am by no means a beginner but this one has got me stumped. So here goes...

I got a VPS package through Namecheap which was the highest one available with Cent OS 7 (now 7.8), WHM + CPanel all installed and ready to go. There is a 5 account limit for the license I currently hold so naturally I have had to use one of the accounts to host a couple of domains outside of that account limit as these can be easily added via the Domains >> Addon Domain feature of CPanel. So there is the context to start off with.

I found through looking at various support articles that in more recent times Node.js applications can be used on domains through the use of either a Plugin which requires CloudLinux. Unfortunately I don't have that, I have Cent OS 7.8 but then I learned of another way using the feature manager in WHM to add something called Application Manager to CPanel in the Software section. So I thought great I can start registering my node.js applications on the domains as necessary. I made sure all the necessary modules were installed as it states in the articles on installation and sure enough managed to get a node.js app running fine on one of the domains, however this particular domain was held as is using one of the 5 accounts. The problem comes next...

I go to the account that holds 2 add-on domains through CPanel and try to register a node.js application installing all dependencies etc as I did before with the first node.js app, however the issue I'm facing is when visiting the application URL I simply get the entire root of the URL listing any folders and/or files within it and not what the app is supposed to output. The app is functioning correctly and is made up of the following:-

app.js - start file for the app
package.json
package-lock.json

Obviously the node_modules folder is there and everything was installed correctly just as the first time on the first domain I tried out on. The correct path is in place and I have tried adding a .htaccess file with the correct lines again as seen in two articles and both were identical in the lines added. I have tried changing the port number and made sure within the .htaccess file that where the sample lists http://127.0.0.1:XXXXX it is changed to reflect the port the app is listening on but it still won't work. In some cases by changing folder permissions I get a 503 error usually when I change the folder to 0711 where it is usually 0750. Nothing seems to help and this is only happening with Add-On domains not with the main domain.

I have also tried going into the conf file with the Virtual Hosts and adding this line:-

ProxyPass http://localhost:3000

This doesn't help either and it was under the correctly located Add-On domain. Just for the FYI I followed the steps in the official installation article:


As said the first app worked fine so don't understand what the problem is when trying to work with Add-On domains. Geez they never make these things easy for us to get working. Will never understand why things can't just work as they're supposed to.

Can anyone help please?
 

cPSamuelM

Technical Analyst Team Lead
Staff member
Nov 20, 2019
182
31
103
USA
cPanel Access Level
Root Administrator
Hello @g_silverfox

If you are only getting a directory listing when you attempt to visit the site, that means something is not configured to properly recognize the correct application startup file. Can you please provide us the contents of the following file?

/etc/apache2/conf.d/userdata/ssl/2_4/$user/$domain.nodejs.conf

Please edit the contents so that your domain name is not exposed.

Best regards
 

g_silverfox

Registered
Jun 10, 2020
4
0
1
Techvill!
cPanel Access Level
Root Administrator
Hello @g_silverfox

If you are only getting a directory listing when you attempt to visit the site, that means something is not configured to properly recognize the correct application startup file. Can you please provide us the contents of the following file?

/etc/apache2/conf.d/userdata/ssl/2_4/$user/$domain.nodejs.conf

Please edit the contents so that your domain name is not exposed.

Best regards
Thank you for replying to me. I performed a find from the bash terminal on the server and that file couldn't be located. I even did a lookup for *.conf and there is nothing that even looks like or resembles that file. There is only one file in that particular directory and it is called basic.conf so I'm at a limbo point again. Really don't understand why these things are so complicated and why they can't just work and perform as expected.
 

cPSamuelM

Technical Analyst Team Lead
Staff member
Nov 20, 2019
182
31
103
USA
cPanel Access Level
Root Administrator

g_silverfox

Registered
Jun 10, 2020
4
0
1
Techvill!
cPanel Access Level
Root Administrator
Hello again @g_silverfox

The nodejs.conf file is created during the installation of the application. It is the last step in the documentation:

https://docs.cpanel.net/knowledge-b....js-application/#create-a-custom-startup-file

I made an assumption you had already created that file, and I apologize for the miscommunication. Can you please try creating this startup file according to the documentation and let us know if it resolves the issue?

Best regards
Hello and thank you for replying again.

Ok so that gives me a bit more insight, however I still need to hammer down exactly what I need to enter and where because that article is very generic and the assumption it makes means someone following it may put the file in the wrong directory so here goes in explaining my structure. So here are two directories for possible location of creating this startup file:

/etc/apache2/conf.d/userdata/ssl/2_4/chevron9
/etc/apache2/conf.d/userdata/ssl/2_4/chevron9/chevron9.pw

At this stage I have to mention that the add-on domain name is actually fbi.ninja which goes under one of the 5 cPanel accounts so am I to assume the startup file would be:

fbi.ninja.nodejs.conf

As fbi.ninja is the add-on domain I'm using that I am having issues with running a nodejs app on. Can I also point out that my startup file is named app.js so I'm unsure as to why it wouldn't be locking onto that fact. Further more when creating the file and specifying the DocumentRoot, the main account that fbi.ninja is held under is pwnedbook.com so the full path to the fbi.ninja domain is:

/home/pwnedbook/public_html/fbi.ninja

The app root directory where app.js is stored:

/home/pwnedbook/public_html/fbi.ninja/app

It also states in the article example these two lines:

PassengerStartupFile index.js
PassengerAppRoot /nodejsapp/example.com

Why is there a separate index.js file? I don't use index.js in my app and for the AppRoot path, given what I've explained in how my structure is set up would mine be:

/home/pwnedbook/public_html/fbi.ninja/app

Please can you help a bit more by explaining where and what. Sorry to be a pain but obviously one thing out of place and it won't work plus I'd also love to know why it isn't locking onto the app.js startup file when that is already there in the /app directory.

Kind Regards

Dave