B4J Tutorial [ABMaterial] Several ABMaterial servers on one IP

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.

____________________________________________________________ FOR CADDY SERVER _____________________________________________________________________

As I mentioned caddy server works much better, simpler and faster than reverse in Apache. There is no need to add modules and make many entries in the Apache config.

Install caddy server on your server and then edit the config file in /etc/caddy/Caddyfile

As an example, I am providing the file structure for several web servers on one machine. I have 5 ABMaterial sites running on one cheap VPS. Among others the Abmaterial demo
Demo ABMaterial

Caddyfile:
# The Caddyfile is an easy way to configure your Caddy web server.
#
# Unless the file starts with a global options block, the first
# uncommented line is always the address of your site.
#
# To use your own domain name (with automatic HTTPS), first make
# sure your domain's A/AAAA DNS records are properly pointed to
# this machine's public IP, then replace ":80" below with your
# domain name.

:80 {
    #for static file
    #root * /var/www/html
    
    #for default server ABMaterial
    reverse_proxy localhost:81
}


page1.mydomain.com:80 {
    # Set this path to your site's directory.
    # root * /usr/share/caddy

    # Enable the static file server.
    # file_server

    # Another common task is to set up a reverse proxy:
    reverse_proxy localhost:8083

    # Or serve a PHP site through php-fpm:
    # php_fastcgi localhost:9000
}

page2.mydomain.com:80 {
    # Set this path to your site's directory.
    # root * /usr/share/caddy

    # Enable the static file server.
    # file_server

    # Another common task is to set up a reverse proxy:
    reverse_proxy localhost:8080

    # Or serve a PHP site through php-fpm:
    # php_fastcgi localhost:9000
}

page1.mydomain.com:80 {
    # Set this path to your site's directory.
    # root * /usr/share/caddy

    # Enable the static file server.
    # file_server

    # Another common task is to set up a reverse proxy:
    reverse_proxy localhost:8888

    # Or serve a PHP site through php-fpm:
    # php_fastcgi localhost:9000
}
B4X:
 
Last edited:

OliverA

Expert
Licensed User
Longtime 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

Well-Known Member
Licensed User
Longtime 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
Longtime 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

Well-Known Member
Licensed User
Longtime 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
Longtime 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.
 

peacemaker

Expert
Licensed User
Longtime User
Thanks for tutorial ! Maybe is there such tutorial for Nginx ?
 

MichalK73

Well-Known Member
Licensed User
Longtime User
Now I am so browsing over new possibilities or solution for Nginx and there is another better method.
Someone mentioned in one forumers reply but I can't find that post.

Now the best solution is to use 'Caddy Server'. Installation is child's play and adding more ABMaterial servers is included in the configuration line. It works very well, quickly without special delving into modules, etc.

HomePage CaddyServer
 
Top