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,427
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,075
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,427
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,075
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,427
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,075
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,322
  • 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,075
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,075
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

Offline Jáder

  • *
  • 1,059
    • LinuxFacil
Re: NodeJS - running w/o SCL
« Reply #15 on: January 28, 2019, 11:08:44 AM »
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.

Hey... please hold on... I'm here to learn, and later I'll document my discoveries!

I can do tests on one of those domains, even without using templates (or TemplatePath) by edit httpd.conf directly.
What I did not understand is why is so complicate to do a http redirect.
I've been reading (a lot) about this feature on Apache and it appears to be so simple:
HEre () I can see:
Code: [Select]
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName myhost.com
ServerAlias ww.myhost.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>

As I can see just two extra lines for proxypass and proxypassreverse... and those are there on my config file.
I'm not sure it these two are required:
Code: [Select]
ProxyPreserveHost On
ProxyRequests Off

If I can make it work, I can create a Template  and put his path on TemplatePath... I think it would be named like "Proxy2NodeJS". But I cannot make it work even changing config file!
As I can see the redirect do not follow directories... just works for "index.html" file .
The https://w8k.jadermarasca.com.br has a temperature app (sample from some site about NodeJS) and even that do not load the CSS file.
As you can see at https://handyman.dulare.com/proxying-node-application-through-apache/ this is possible.
I just don't know about modules.

Remember: togheter we're better than alone!

EDIT: I moved one step forward!
Changed my template file /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/27ProxyNodeJS to
Code: [Select]
{
    use esmith::DomainsDB;
    my $domains = esmith::DomainsDB->open_ro;

    my $nodeport = $domains->get_prop($virtualHost, "NodePort") || "disabled";
    return "    # skipping NodeJS redirect - no NodePort parameter\n" unless not $nodeport eq "disabled";

    $OUT .= "    # NodeJS port redirect\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPreserveHost On\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyRequests Off\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPass / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPassReverse / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled';

}

Now sample app of temperature works, load CSS (it's a lot better in visual!).
I'll try to learn about the NodeJs requirements and update/create wiki page about it.
« Last Edit: January 28, 2019, 11:20:25 AM by Jáder »
...

Offline ReetP

  • *
  • 2,075
Re: NodeJS - running w/o SCL
« Reply #16 on: January 28, 2019, 02:29:36 PM »
Hey... please hold on... I'm here to learn, and later I'll document my discoveries!

You are not really learning. You are skipping over things without understanding them.

This is turning in to a classic X Y problem.

http://xyproblem.info/

Quote
User wants to do X.
User doesn't know how to do X, but thinks they can fumble their way to a solution if they can just manage to do Y.
User doesn't know how to do Y either.
User asks for help with Y.
Others try to help user with Y, but are confused because Y seems like a strange problem to want to solve.
After much interaction and wasted time, it finally becomes clear that the user really wants help with X, and that Y wasn't even a suitable solution for X.


Quote
I can do tests on one of those domains, even without using templates (or TemplatePath) by edit httpd.conf directly.

Of course you can for testing, but you want a permanent solution don't you? And that is where you are struggling.

Sure, you can do it for one domain, but that isn't what you asked to do. You want to do it for three different domains with slightly differing configs. That is not so simple. Well, it is if you understand what is happening.

Quote
What I did not understand is why is so complicate to do a http redirect.

Because you don't understand httpd configurations, and you don't understand how SME works and are not taking the time to try and learn. Believe me, I am no genius at it, but I sat down, read code and worked it out.

You want something complicated to be easy. Unfortunately that isn't going to happen.

Quote
I've been reading (a lot) about this feature on Apache and it appears to be so simple:
HEre () I can see:
Code: [Select]
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName myhost.com
ServerAlias ww.myhost.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Just because it 'appears' to be simple does not mean that it is.

Yup - easy for one domain isn't it ? But that still isn't what you want to do.

Quote
If I can make it work, I can create a Template  and put his path on TemplatePath... I think it would be named like "Proxy2NodeJS". But I cannot make it work even changing config file!

Because you aren't reading what I wrote or trying to work out how it works.

Quote
As I can see the redirect do not follow directories... just works for "index.html" file .
The https://w8k.jadermarasca.com.br has a temperature app (sample from some site about NodeJS) and even that do not load the CSS file.
As you can see at https://handyman.dulare.com/proxying-node-application-through-apache/ this is possible.
I just don't know about modules.

EDIT: I moved one step forward!
Changed my template file /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/27ProxyNodeJS to
Code: [Select]
{
    use esmith::DomainsDB;
    my $domains = esmith::DomainsDB->open_ro;

    my $nodeport = $domains->get_prop($virtualHost, "NodePort") || "disabled";
    return "    # skipping NodeJS redirect - no NodePort parameter\n" unless not $nodeport eq "disabled";

    $OUT .= "    # NodeJS port redirect\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPreserveHost On\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyRequests Off\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPass / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPassReverse / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled';

}


Now, why do you think that only works for one domain?

If you read what I wrote above about Rocketchat you might understand.

I'll try it once more. Please go and look in the directories and find this stuff.

You have a STOCK directory.

/etc/e-smith/templates/etc/httpd/conf/httpd.conf/ProxyPassVirtualHosts

You can then add a TemplatePath "ProxyPassVirtualHosts" which forces SME to look in the above directory for templates.

This will enable simple proxying for a domain.

To do something more complicated you can create your own directories and put your own custom templates in there to create you own virtual host

So as per Rocketchat I have:

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

Then I set the TemplatePath for a domain to "ProxyPassVirtualRocketchat"

SME will now look in that directory for templates.

I could call it say:

/etc/e-smith/templates/etc/httpd/conf/httpd.conf/VirtualHost-1

Set the TemplatePath for a domain to "VirtualHost-1"

Now copy the first three templates over from ProxyPassVrtualHosts to VirtualHosts-1. These will set up the new virtualhost. You can then add your other options with additional templates

00Setup
02ServerName
03ServerAlias

Then I have (not all of this may be necessary)

04ProxyPassContent


Code: [Select]
{
    use esmith::DomainsDB;
    use esmith::ConfigDB;
    my $domainsDB = esmith::DomainsDB->open_ro;
    my $configDB = esmith::ConfigDB->open_ro;
    my $target  = $domainDB->get_prop($virtualHost, 'ProxyPassTarget') || 'http://127.0.0.1:3000';
    $target  =~ s~http[s]*://~~g;
    my $SSLProxy = $config->get_prop('rocketchat', 'SSLProxy') || '';

    if ( $port eq "80" ) {
    $OUT .= "# Host $virtualHost $target\n";
        $OUT .= "    # Redirect Letsencrypt queries\n";
        $OUT .= "    RewriteRule ^/.well-known/acme-challenge(/.*|\$) https://%{HTTP_HOST}/.well-known/acme-challenge\$1 [L,R]\n";
        $OUT .= "    # Everything else goes to https\n";
        $OUT .= "    RewriteRule ^/(.*|\$) https://%{HTTP_HOST}/ [R,L]\n";

    }

    if ( $port eq "443" ) {

        $OUT .= "    # SSL Directives\n";
        $OUT .= "    SSLEngine on\n";
        $OUT .= "    ProxyPreserveHost On\n";
        $OUT .= "    SetEnv proxy-initial-not-pooled 1\n";
        $OUT .= "    # Letsencrypt - proxy bypass\n";
        $OUT .= "    ProxyPass /.well-known/acme-challenge/ !\n";
        $OUT .= "    ProxyPassMatch ^.*/sockjs/(.*)/websocket ws://$target/sockjs/\$1/websocket\n";
        $OUT .= "    ProxyPass /websocket ws://$target/websocket\n";
        $OUT .= "    ProxyPass / http://$target/ retry=1 acquire=3000 timeout=600 Keepalive=on\n";
        $OUT .= "    ProxyPassReverse / http://$target/\n";
        $OUT .= "    \n";
    }
}

When you expand the httpd.conf file you will find a new virtualhost for your domain. My Rocket config creates these:

Code: [Select]
<VirtualHost 0.0.0.0:80>

    ServerName chat.mydomain.com
    ServerAlias
    RewriteEngine on
    RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
    RewriteRule .* - [F]

    # Redirect Letsencrypt queries
    RewriteRule ^/.well-known/acme-challenge(/.*|$) https://%{HTTP_HOST}/.well-known/acme-challenge$1 [L,R]
    # Everything else goes to https
    RewriteRule ^/(.*|$) https://%{HTTP_HOST}/ [R,L]

</VirtualHost>


<VirtualHost 0.0.0.0:443>

    ServerName chat.mydomain.com
    ServerAlias

    # SSL Directives
    SSLEngine On
    ProxyPreserveHost On
    SetEnv           proxy-initial-not-pooled 1
    # Letsencrypt - proxy bypass
    ProxyPass /.well-known/acme-challenge/ !
    # Websockets
    ProxyPassMatch ^/sockjs/(.*)/websocket ws://localhost:3000/sockjs/$1/websocket
    ProxyPass /websocket ws://127.0.0.1:3000/websocket
    ProxyPass / http://127.0.0.1:3000/ retry=1 acquire=3000 timeout=600 Keepalive=On
    ProxyPassReverse / http://127.0.0.1:3000/

</VirtualHost>

Note that may not be perfect or exact but should give you an idea.

I could add additional template directories VirtualHost-2 VirtualHost-3 etc and paths as I want them, each one creating a new virtual host.

Quote
I'll try to learn about the NodeJs requirements and update/create wiki page about it.
https://wiki.contribs.org/NodeJS#For_SME_9


...
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 #17 on: January 29, 2019, 10:23:26 AM »
(...)
I'll try it once more. Please go and look in the directories and find this stuff.
You have a STOCK directory.
/etc/e-smith/templates/etc/httpd/conf/httpd.conf/ProxyPassVirtualHosts
You can then add a TemplatePath "ProxyPassVirtualHosts" which forces SME to look in the above directory for templates.
This will enable simple proxying for a domain.

Thanks by your new explanation.
I finally understand why a TemplatePath and find out I really do not need it.
As I was thinking from beginning, NodeJS just need to port redirect. One redirect by app.
So I just need to create a new variable (NodePort) to specify that port and use a custom fragment template file /etc/e-smith/templates-custom/etc/httpd/conf/httpd.conf/VirtualHosts/27ProxyNodeJS with:
Code: [Select]
{
    use esmith::DomainsDB;
    my $domains = esmith::DomainsDB->open_ro;

    my $nodeport = $domains->get_prop($virtualHost, "NodePort") || "disabled";
    return "    # skipping NodeJS redirect - no NodePort parameter\n" unless not $nodeport eq "disabled";

    $OUT .= "    # NodeJS port redirect\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPreserveHost On\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyRequests Off\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPass / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled';
    $OUT .= "    ProxyPassReverse / http://localhost:$nodeport/\n" unless $nodeport eq 'disabled';

}
the variable can be set by using this db command:
Code: [Select]
db domains setprop w8k.portalgap.com.br NodePort 3003
and expand new template and restart
Code: [Select]
expand-template /etc/httpd/conf/httpd.conf
/etc/init.d/httpd-e-smith restart
That's all. It's working.
The configuration works for any (as far I have tested) NodeJS app even code is not clean because it's generated all redirects to /server-manager :980/server-manager and so on... but that it's a NFR for SME generate those only for main domain, so it's another discussion.
If you need SSL using LetsEncrypt you can follow appropriate wiki page.

I'll document all these NodeJS thing in wiki page ASAP.
« Last Edit: January 29, 2019, 10:26:51 AM by Jáder »
...

Offline ReetP

  • *
  • 2,075
Re: NodeJS - running w/o SCL
« Reply #18 on: January 29, 2019, 03:30:48 PM »
Can you go back and check your code?

I believe 'unless' should be used like

unless ('something' eq 'somethingelse')

And this?

Code: [Select]
return "    # skipping NodeJS redirect - no NodePort parameter\n" unless not $nodeport eq "disabled";
How does the 'not' work in this scenario?

Something like this might be better?

Code: [Select]
return "Blah" unless ($nodeport ne "disabled");
And then something like this:

Code: [Select]
$OUT .= "    ProxyPreserveHost On\n" unless ($nodeport eq "disabled");
However, if it passes the first 'return' one presumes that you have a port set so really the following 'unless' parts are irrelevant - you may as well just output.

Also, be consistent with your use of " or '

Please and make sure you test code thoroughly before putting it on the wiki to try and ensure it is bug free.

...
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,075
Re: NodeJS - running w/o SCL
« Reply #19 on: January 29, 2019, 03:32:22 PM »
There's lots of stuff about but this seemed quite good

https://www.perltutorial.org/perl-unless/
...
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,075
Re: NodeJS - running w/o SCL
« Reply #20 on: January 29, 2019, 03:39:17 PM »
Can you also explain the last line in the wiki please - it doesn't really make much sense.

"It's possible to access using SME with one LetsEncrypt certificate by directory/port"

It might be also good to show a snippet from httpd.conf to see what the new code looks like.
...
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