B4J Tutorial [ABMaterial] Several ABMaterial servers on one IP

MichalK73

Active Member
Licensed User
Hello.

I was struggling to see several ABMaterial servers visible from one IP on one port. I use it because I have one VPS test server for clients and I put there test versions for them. Each time I gave them a different port for their different ABMAterial server. As you know, each ABMaterial server must have a different port or conflict will occur.

Scheme:
1. Apache works on port 80, e.g. WEB page
2. App1 ABMaterial works on port 8080 (AppName - test1)
3. App2 ABMaterial works on port 8888 (AppName - test2)

With this arrangement we have:
http://server.com - WEB page
http://server.com:8080/test1 - App1
http://server.com:8888/test2 - App2

Unfortunately, some client companies' proxies did not allow ports other than 80,443. The solution is to use an Apache proxy.

Required modules for Apache:
mod_proxy_connect, mod_proxy_express, mod_proxy_fcgi, mod_proxy_fdpss, mod_proxy_ftp, mod_proxy_http, mod_proxy_scgi, mod_proxy_wstunnel, mod_proxy_ajp

Tested on CentOS 7. All these modules are in standard but in version 6 there is no 'wstunnel' and you need to search the web or compile manually.

We set up virtual servers in httpd.conf.

httpd.conf:
<VirtualHost *:80>
    ServerName app1.server.com
    ProxyPreserveHost On
    ProxyRequests Off
    RewriteEngine On
    ProxyPass /test1 http://localhost:8888/test1
    ProxyPass /css http://localhost:8888/css
    ProxyPass /js http://localhost:8888/js
    ProxyPass /font http://localhost:8888/font
    ProxyPass /ws ws://localhost:8888/ws
    ServerAlias app1
</VirtualHost>


<VirtualHost *:80>
    ServerName app2.server.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass /test2 http://localhost:8080/test2
    ProxyPass /css http://localhost:8080/css
    ProxyPass /js http://localhost:8080/js
    ProxyPass /font http://localhost:8080/font
    ProxyPass /ws ws://localhost:8080/ws
    ServerAlias app2
</VirtualHost>
After restarting the Apache server we have the result in the form:
1. http://server.com - WEB website
2. http://app1.server.com/test1 - webapp ABMaterial (AppName test1)
3. http://app2.server.com/test2 - webapp ABMaterial (AppName test2)

In this way, we get rid of the port address because it is automatically handled by the Apache proxy. Works equally well at cloudflare.com where we can force SSL from CF and on our side remains without SSL. You might as well enable SSL on your servers.

Tips: using 'mod_proxy_balancer' we can make our own balancer server by distributing the load over several machines with identical ABMaterial servers.

Regards
 
Last edited:

OliverA

Expert
Licensed User
I can see from the configuration how Apache knows where to sent access for /test1 and /test2 properly (since the path portion is unique and therefore Apache can distinguish between them). But, how does Apache know how to properly handle /css, /js, /font, and /ws? These are not unique path names for the given proxy mappings (meaning /css is mapped both to port 8080 and 8888).
 

MichalK73

Active Member
Licensed User
I can see from the configuration how Apache knows where to sent access for /test1 and /test2 properly (since the path portion is unique and therefore Apache can distinguish between them). But, how does Apache know how to properly handle /css, /js, /font, and /ws? These are not unique path names for the given proxy mappings (meaning /css is mapped both to port 8080 and 8888).
Well, I forgot to add ServerName to VirtualHost :)
Now it's ok
 

codie01

Active Member
Licensed User
Thanks Michal for the awesome tutorial.

I have set my httpd.conf up as per your example and the first virtual host works fine, however not the second virtual host. If I remove the first virtual host from httpd.conf then the second one works fine. Please advise what I am doing wrong, thanks.

my virtual host httpd.conf

B4X:
<VirtualHost *:80>
    ServerName go.xxxxxxxxx.com
    ProxyPreserveHost On
    ProxyRequests Off
    RewriteEngine On
    ProxyPass /rose http://localhost:51042/rose
    ProxyPass /css http://localhost:51042/css
    ProxyPass /js http://localhost:51042/js
    ProxyPass /font http://localhost:51042/font
    ProxyPass /ws ws://localhost:51042/ws
    ServerAlias go
</VirtualHost>


<VirtualHost *:80>
    ServerName bgw.xxxxxxxxx.com
    ProxyPreserveHost On
    ProxyRequests Off
    ProxyPass /backgroundWorker http://localhost:51111/backgroundWorker
    ProxyPass /css http://localhost:51111/css
    ProxyPass /js http://localhost:51111/js
    ProxyPass /font http://localhost:51111/font
    ProxyPass /ws ws://localhost:51111/ws
    ServerAlias bgw
</VirtualHost>
 

MichalK73

Active Member
Licensed User
Are all required Apache modules on the system?
You may have modified the general Apache settings which affect it. I do not know.
I'm working on the standard CentOS httpd.conf file. I have already set up several redirects and they all work correctly.
 

codie01

Active Member
Licensed User
Hi Michal I have solved it!, replaced backgroundWorker appname in abmaterial to the same as jar name and changed httpd.conf and it all works. Thank you very much for taking the time to write this tutorial.
 
Top