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/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.
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.
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.
I've been reading (a lot) about this feature on Apache and it appears to be so simple:
HEre () I can see:
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.
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.
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
{
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
{
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:
<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.
I'll try to learn about the NodeJs requirements and update/create wiki page about it.
https://wiki.contribs.org/NodeJS#For_SME_9