Koozali.org formerly Contribs.org

NodeJS - running w/o SCL

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
NodeJS - running w/o SCL
« on: December 27, 2018, 01:49:57 AM »
I'm trying to put NodeJs to work without SCL.

I've been sucesfull using NodeJS v11.5.0 + PM2.. and I'll document it later (I'm taking notes!)

But right now I'm trying to get automatic support of app by create a new parameter on domains database to hold the NodeJS port number. So I did:
 
Code: [Select]
: db domains setprop w8k.jadermarasca.com.br NodePort 3001and created a new fragment template:
Code: [Select]
/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/ProxyPassVirtualHosts/27ProxyNodeJSwith
Code: [Select]
{
    use esmith::DomainsDB;
    my $domains = esmith::DomainsDB->open_ro;

    my $nodeport = $domains->get_prop($virtualHost, "NodePort") || "disabled";

    $OUT = "";

    $OUT .= "    ProxyPass / http://localhost:$nodeport\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPassReverse / http://localhost:$nodeport\n" unless $nodeport eq 'disabled';
    $OUT .= "    #Jm END";
    return "    # Jm RETURN = skipping NodeJS NodePort \n" unless not $nodeport eq "disabled";
}

but even after a
Code: [Select]
expand-template /etc/httpd/conf/httpd.conf I cannot find the "Jm" marker . Note as AFAIK one of them should be added to httpd.conf even if it do not find any port on NodePort property.

So... please tell me what am I doing wrong... Thank you.
...

Offline mmccarn

  • *
  • 2,415
Re: NodeJS - running w/o SCL
« Reply #1 on: December 27, 2018, 12:30:12 PM »
The templates in ProxyPassVirtualHosts are activated by the domain property "ProxyPassTarget" and "TemplatePath":
https://wiki.contribs.org/SME_Server:Documentation:ProxyPass#ProxyPass_a_domain

To get your new template fragment included in httpd.conf you'd need to set "ProxyPassTarget" on the domain in question -- but then you could include the Node port and eliminate the custom template fragment:
Code: [Select]
db domains setprop w8k.jadermarasca.com.br ProxyPassTarget 'http://localhost:3001/'
db domains setprop w8k.jadermarasca.com.br TemplatePath ProxyPassVirtualHosts

Try moving your fragment into /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts instead.

Offline ReetP

  • *
  • 2,054
Re: NodeJS - running w/o SCL
« Reply #2 on: December 27, 2018, 04:45:03 PM »
You can use the NodeJS repo....

Check here:

https://wiki.contribs.org/User:ReetP

Just install the 'n' version manager to change version. Have a look at the rocketchat pages for some node & httpd/proxy stuff.

...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
Re: NodeJS - running w/o SCL
« Reply #3 on: December 28, 2018, 10:02:46 AM »
The templates in ProxyPassVirtualHosts are activated by the domain property "ProxyPassTarget" and "TemplatePath":
https://wiki.contribs.org/SME_Server:Documentation:ProxyPass#ProxyPass_a_domain

To get your new template fragment included in httpd.conf you'd need to set "ProxyPassTarget" on the domain in question -- but then you could include the Node port and eliminate the custom template fragment:
Code: [Select]
db domains setprop w8k.jadermarasca.com.br ProxyPassTarget 'http://localhost:3001/'
db domains setprop w8k.jadermarasca.com.br TemplatePath ProxyPassVirtualHosts

Try moving your fragment into /etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHosts instead.

Thank you by your tip about to move fragment to VirtualHost. It's working now.
I'm just do not understand about to use ProxyPass: am I doing that on wrong way (or a mor difficult way) ??

...

Offline mmccarn

  • *
  • 2,415
Re: NodeJS - running w/o SCL
« Reply #4 on: December 28, 2018, 01:05:13 PM »
I'm just do not understand about to use ProxyPass: am I doing that on wrong way (or a mor difficult way) ??

That depends on your actual requirements and objectives.

If the existing proxypass functionality works for your use case, then yes - creating a new custom template (and presumably getting it accepted by the devs so you don't have to maintain it manually forever) is more difficult than using the existing system.

If there is some aspect of the current system that is not working for you then we'd have to know what that is and weigh the pros and cons of creating a new template fragment vs adjusting the existing fragment.

If you can get the result you need with no (or minor) modifications to the existing system, it might be less work to adjust the existing system rather than creating a new system -- but choosing incremental solutions time after time ultimately results in a more complex and convoluted system than if you stop and do some conscious system design now and then.

...and finally -- no system is done (in my opinion) until the wiki is updated - so you need to include in your easier/harder/right/wrong calculations the effort to find or create a home on the wiki for documenting the new system...

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
Re: NodeJS - running w/o SCL
« Reply #5 on: January 27, 2019, 12:46:51 PM »
That depends on your actual requirements and objectives.

These are my requirements:
1) I have one fixed IP and several site to host there.
2) most of those sites will be NodeJS
3) user must type only URL, without any port: https://w8k.jadermarasca.com.br  to test.
4) apache/nginx must take care of redirect and everything must work transparently to users

I'm testing using w8k as hostname for domains jadermarasca.com.br, moresco-contabilidade.com.br , portalgap.com.br and valleruaro.adv.br.

So access to w8k to any of those domains should works.
I've it working for simple apps (without ANY other folder/files than basic initial website) : https://w8k.jadermarasca.com.br and https://w8k.moresco-contabilidade.com.br ... and even these are do not load css !

What I did:
a) I created 27NodeJS (see above) to get port redirect (ProxyPass and reverse)
b) each NodeJS app works on one different port : 3001 is jadermarasca.com.br , 3002 is moresco-contabilidade.com.br , 3003 is portalgap.com.br
c) I event tried to redirect on index.html ... it works for initial page, not for anything else
d) I add this to config file:

Code: [Select]
<VirtualHost 0.0.0.0:443>
    ServerName w8k.portalgap.com.br
    ServerAlias ftp.w8k.portalgap.com.br mail.w8k.portalgap.com.br proxy.w8k.portalgap.com.br serverlocal.w8k.portalgap.com.br wpad.w8k.portalgap.com.br www.w8k.portalgap.com.br
(...)
    # Jm
    RewriteCond %{HTTP_HOST} w8k.portalgap.com.br
    RewriteRule ^(.*)$ http://w8k.portalgap.com.br:3003/$1 [L,R]

Or is this impossible ?

Thanks.
« Last Edit: January 27, 2019, 01:34:58 PM by Jáder »
...

Offline ReetP

  • *
  • 2,054
Re: NodeJS - running w/o SCL
« Reply #6 on: January 27, 2019, 02:15:40 PM »
Yes it is probably possible but you need to understand more about proxy pass templates/virtualhosts

The key bit is the TemplatePath...... this can either be an existing dir or one you create yourself.

In Rocket I actually create a new dir and put specific virtual host templates in there and set the TemplatePath to 'ProxyPathRocketchat'

You need a dir like this

/etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf
/ProxyPassVirtualRocketchat

 ll
total 16
-rw-r--r-- 1 root root   30 Mar 14  2006 02ServerName
-rw-r--r-- 1 root root  235 Sep  7  2017 03ServerAlias
-rw-r--r-- 1 root root  382 Jun 25  2018 26RewriteTrace
AndTrack
-rw-r--r-- 1 root root 1808 Jul 10  2018 ProxyPassConte
nt

db domains show

chat.mydomain.com=domain
    Content=Primary
    Description=Chat Server
    Nameservers=localhost
    ProxyPassTarget=http://127.0.0.1:3000/
    TemplatePath=ProxyPassVirtualRocketchat
    letsencryptSSLcert=enabled

Note this:

ProxyPassTarget=http://127.0.0.1:3000/
TemplatePath=ProxyPassVirtualRocketchat


Rinse & repeat.

On mobile at the minute so can't do much more to help right now.

I can post some templates tomorrow.

...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline mmccarn

  • *
  • 2,415
Re: NodeJS - running w/o SCL
« Reply #7 on: January 27, 2019, 02:49:09 PM »
It looks like the domain in your code sample was created in server-manager, which according to this note on the proxypass wiki page will cause problems (I don't know why):

Note:
   If you have added the internal or external server's domain name as a virtual domain on the SME Server, you must remove it prior to issuing these commands. The server-manager domains panel will show the proxy pass entry but you will not be able to edit it, see bugzilla:1612

Here's what I did to create a proxypass entry for "ec.mysmeserver.us" pointing to Etherpad, running on port 9001 on the same server (My etherpad is configured to use SSL, so the ProxyPassTarget requires "https"):

Code: [Select]
db domains delete ec.mysmeserver.us
db domains set ec.mysmeserver.us domain ProxyPassTarget 'https://localhost:9001/' TemplatePath ProxyPassVirtualHosts
signal-event domain-modify ec.mysmeserver.us

I can now access Etherpad at http://ec.mysmeserver.us or https://ec.mysmeserver.us from my local network.
- tinydns has been updated to host dns for the domain "ec.mysmeserver.us"
- there is an A record for ec.mysmeserver.us pointing to the LAN IP of the SME server
- /etc/httpd/conf/httpd.conf contains proxypass template fragments for the new domain

NOTES
- I have https enabled for my etherpad because the proxy server is on a different network host.  When I ran etherpad using the SME proxypass, I left etherpad on http.
- If your NodeJS applications need to be running on https, you can use ReetP's suggestion for a new template path to contain templates that do that.

Reference info:
Code: [Select]
# db domains show ec.mysmeserver.us
ec.mysmeserver.us=domain
    ProxyPassTarget=https://localhost:9001/
    TemplatePath=ProxyPassVirtualHosts

Quote from: /etc/httpd/conf/httpd.conf
<VirtualHost 0.0.0.0:80>

    ServerName ec.mysmeserver.us
    ServerAlias

    RewriteEngine on
    RewriteCond %REQUEST_METHOD ^(TRACE|TRACK)
    RewriteRule .* - [F]

    ProxyPass / https://localhost:9001/
    ProxyPassReverse / https://localhost:9001/
</VirtualHost>


<VirtualHost 0.0.0.0:443>

    ServerName ec.mysmeserver.us
    ServerAlias

    RewriteEngine on
    RewriteCond %REQUEST_METHOD ^(TRACE|TRACK)
    RewriteRule .* - [F]

    SSLEngine On
    ProxyPass / https://localhost:9001/
    ProxyPassReverse / https://localhost:9001/
</VirtualHost>

Offline ReetP

  • *
  • 2,054
Re: NodeJS - running w/o SCL
« Reply #8 on: January 27, 2019, 04:59:11 PM »
It was a trick.shown me by Tony Keane years ago and works perfectly :-)
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline Jean-Philippe Pialasse

  • *
  • 1,306
  • aka Unnilennium
    • http://smeserver.pialasse.com
Re: NodeJS - running w/o SCL
« Reply #9 on: January 27, 2019, 06:05:26 PM »
just built new version of extrarepositories with node repo

https://wiki.contribs.org/Extrarepositories#Version

will be soon in smetest, please report to https://bugs.contribs.org/show_bug.cgi?id=10727 if it is working good for you !

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
Re: NodeJS - running w/o SCL
« Reply #10 on: January 27, 2019, 10:20:20 PM »
Yes it is probably possible but you need to understand more about proxy pass templates/virtualhosts

The key bit is the TemplatePath...... this can either be an existing dir or one you create yourself.

I really do not understand what is the TemplatePath... it's a path for custom files to build a new entry ?
...

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
Re: NodeJS - running w/o SCL
« Reply #11 on: January 27, 2019, 10:27:18 PM »
It looks like the domain in your code sample was created in server-manager, which according to this note on the proxypass wiki page will cause problems (I don't know why):
Yes , it was created under server-manager.
I need a virtual domain so I can point out the target directory of content AND use it as virtual domain for e-mail.
If I delete the virtual domain from server-manager (or using db domain delete virtualdomain.com) shouldn't I loose those  features ?

Quote
Here's what I did to create a proxypass entry for "ec.mysmeserver.us" pointing to Etherpad, running on port 9001 on the same server (My etherpad is configured to use SSL, so the ProxyPassTarget requires "https"):

Code: [Select]
db domains delete ec.mysmeserver.us
db domains set ec.mysmeserver.us domain ProxyPassTarget 'https://localhost:9001/' TemplatePath ProxyPassVirtualHosts
signal-event domain-modify ec.mysmeserver.us

I can now access Etherpad at http://ec.mysmeserver.us or https://ec.mysmeserver.us from my local network.
- tinydns has been updated to host dns for the domain "ec.mysmeserver.us"
- there is an A record for ec.mysmeserver.us pointing to the LAN IP of the SME server
- /etc/httpd/conf/httpd.conf contains proxypass template fragments for the new domain

I need to access them from internet.
I'd prefer to enable SSL (lets encrypt SSL cert) on all sites.

Quote
NOTES
- I have https enabled for my etherpad because the proxy server is on a different network host.  When I ran etherpad using the SME proxypass, I left etherpad on http.
- If your NodeJS applications need to be running on https, you can use ReetP's suggestion for a new template path to contain templates that do that.

Reference info:
Code: [Select]
# db domains show ec.mysmeserver.us
ec.mysmeserver.us=domain
    ProxyPassTarget=https://localhost:9001/
    TemplatePath=ProxyPassVirtualHosts

Using your commands I have got at same point:
Code: [Select]
[root@n40l ~]# db domains show w8k.portalgap.com.br
w8k.portalgap.com.br=domain
    Nameservers=internet
    ProxyPassTarget=https://localhost:3003/
    TemplatePath=ProxyPassVirtualHosts

and got this code generated:
Code: [Select]

<VirtualHost 0.0.0.0:443>

    ServerName w8k.portalgap.com.br
    ServerAlias ftp.w8k.portalgap.com.br mail.w8k.portalgap.com.br proxy.w8k.portalgap.com.br serverlocal.w8k.portalgap.com.br wpad.w8k.portalgap.com.br www.w8k.portalgap.com.br

    RewriteEngine on
    RewriteCond %REQUEST_METHOD ^(TRACE|TRACK)
    RewriteRule .* - [F]

    SSLEngine On
    ProxyPass / https://localhost:3003/
    ProxyPassReverse / https://localhost:3003/
</VirtualHost>


But it just do not work! hehehe...
I did not understand the TemplatePath parameter and what is the ProxyPassVirtualHosts
« Last Edit: January 27, 2019, 10:28:56 PM by Jáder »
...

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
Re: NodeJS - running w/o SCL
« Reply #12 on: January 27, 2019, 10:31:42 PM »
just built new version of extrarepositories with node repo

https://wiki.contribs.org/Extrarepositories#Version

will be soon in smetest, please report to https://bugs.contribs.org/show_bug.cgi?id=10727 if it is working good for you !

Could you please elaborate... Your information is useless to me... I really do not know what to do with it! Sorry!
...

Offline ReetP

  • *
  • 2,054
Re: NodeJS - running w/o SCL
« Reply #13 on: January 28, 2019, 10:30:37 AM »
I really do not understand what is the TemplatePath... it's a path for custom files to build a new entry ?

I did show you how to do this above.

You have to understand that you are trying to do something quite complicated. That means you really need to go and learn how this works by reading some of the code.

TemplatePath will point to a path for a custom virtualhost with a name of your choice.

If you bother to look in the templates directory you will see a default directory called ProxyPathVirtialHosts.

But you can create your own directories with each virtualhost having its owm settings.

So if you read what I wrote I created a directory for rocketchat and added my own proxy templates in there and set TemplatePath to point to it.

You can have 3 directories and 3 TemplatePaths, one for each domain.

Get yourself a test machine, read carefully, and test.

Until you start reading code and fumdamentally understand how this works (exactly what I had to do) you are going to struggle.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation

Offline ReetP

  • *
  • 2,054
Re: NodeJS - running w/o SCL
« Reply #14 on: January 28, 2019, 10:32:01 AM »
Could you please elaborate... Your information is useless to me... I really do not know what to do with it! Sorry!

Read the wiki, read the bug.

In short this rpm will set up.the NodeJS repo for you. No need to use SCL.
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation