B4J Question Re: To work with a Domain name

sivakrith

Member
Licensed User
Hello,

We developed and copied a web application, with b4j and hosted it in a web server (VPS, Ubuntu Linux server 20.04). It works fine with the ipaddress mode (http://ipaddress:port). Now we want to access this site with a domain name (eg. http://www.mysite.com).

1. For this what settings we need to do in Linux and / or this B4J application ?
2. This will be a multi-tenant one, where we plan to host multiple-domain names points to this server. How to accomplish this task ? We copied this b4j application in folder. Similarly we'll be copy all b4j application(s) in different folder and with different port numbers. Now we need to know how to setup this in Linux ?

We're not sure whether this is the right forum for linux settings for B4J application, as B4J works in a different way (without a webserver), I thought I can get your expert opinions in setting up our VPS server.

Happiness Always
BKR Sivaprakash
 

tufanv

Expert
Licensed User
1. For this what settings we need to do in Linux and / or this B4J application ?
First you need to edit virtualhosts file of apache on ubuntu. Check this tutorial : https://www.digitalocean.com/commun...ache-virtual-hosts-on-ubuntu-18-04-quickstart
This will be a multi-tenant one, where we plan to host multiple-domain names points to this server. How to accomplish this task ?
you can create many different virtual hosts file and activate them son lets say in linux's var/www/html/app1 folder you will have appplication 1 , one of your virtual host file must point to this directory lets say example1.com.

Another path will be var/www/html/app2, and another virtualhosts file will be activated in apache config so example2.com will point to var/www/html/app2 which inludes your application 2's files etc..
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
First you need to edit virtualhosts file of apache on ubuntu. Check this tutorial : https://www.digitalocean.com/commun...ache-virtual-hosts-on-ubuntu-18-04-quickstart

you can create many different virtual hosts file and activate them son lets say in linux's var/www/html/app1 folder you will have appplication 1 , one of your virtual host file must point to this directory lets say example1.com.

Another path will be var/www/html/app2, and another virtualhosts file will be activated in apache config so example2.com will point to var/www/html/app2 which inludes your application 2's files etc..
I think this is an incorrect advice, apache virtual host helps to serve static files. What the op needs is a reverse proxy, apache can do that too but it is b not the best solution.
https://www.digitalocean.com/commun...er-as-reverse-proxy-using-mod_proxy-extension

You better look at nginx, caddy or traefik. Reverse proxing is easy but you have to set everything up and that could take time.

I have a server with more than 5 b4j apps each serving its own domain, i did that with docker, docker-compose and traefik but my setup could have been good with a simple reverse proxy like nginx
 
Upvote 0

sivakrith

Member
Licensed User
Thanks tufanv and Enrique for your time and reply.

I'm new to B4X, Web and in learning stages only. May be my question will be basic.

I purchased one B4J application that I hosted in my webserver (Ubuntu Linux 20.04) and I could access that website with ipaddress:port values (eg. 204.67.78.1:77777). It's working fine. Now I need to access the same with a domain name instead of ipaddress:port format.

1. For this, should there be a webserver (apache) anyway ? No idea why this is required. Note my port is not 80.
2. My expected concurrent users for the first year will be couple of hundreds (max) only. Do we need a reverse proxy setup for this load ?
3. Docker. My current webserver doesn't support this. Will look into it in future.

Happiness Always
BKR Sivaprakash
 
Upvote 0

oparra

Well-Known Member
Licensed User
First, if you want to have multiple domains on your server, you need to do a little research on this:


Jetty domain


 
  • Like
Reactions: udg
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
For this, should there be a webserver (apache) anyway ?
No its not needed. B4j holds a server, just change the A record to your server and you will be able to access. If you use port 7777 then access as domain.com:7777 if you dont want write port then use port 80

My expected concurrent users for the first year will be couple of hundreds (max) only. Do we need a reverse proxy setup for this load ?
No, not at all. Reverse proxy is only for hosting more than one app on the same port, it has nothing to do with performance.


Docker. My current webserver doesn't support this. Will look into it in future.
Any linux server from a couple of years supports docker, you dont need it in the first steps dont worry about that.
 
  • Like
Reactions: HAH
Upvote 0

HAH

Well-Known Member
Licensed User
It is very simple man... Just go to your domains control panel >> dns zone editor >> change ip address in A record to your server ip address ONLY.
I'm 20 years expert in domains & hosting, so you can ask anything.
 
Upvote 0

sivakrith

Member
Licensed User
Thanks.
1. Modified A record in domain control panel, pointed to the required ip address.
2. Copied all required files in var/www/domainname.com/public_html folder
3. Created required conf files [domainname.com.conf] pointing the document root to the above folder.

It worked.

My doubt(s).

1. Should the folder be in /var/www/domainname.com/public_html ? Can't we create some other folder(s) in the root and point that folder in the conf file ?
2. Apache is required in the above setup, it seems. I don't want my users to type port number along with the domain name. Then how to make it to work with port 80 ?
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
hi!
in your setup you are only using apache, you are not using b4j server at all.

Can't we create some other folder(s) in the root and point that folder in the conf file ?
with b4j you in theory can turn any folder into a website but it must have the required permissions, common practice is to use the file.dirapp folder as parent of a www folder that will be your website.

Apache is required in the above setup
yes correct, you are not using the b4j server.

s. I don't want my users to type port number along with the domain name.
disable apache and change the port on the b4j app to 80 and you will not need the port.

Then how to make it to work with port 80
dim server as server
server.port = 80
 
Upvote 0

sivakrith

Member
Licensed User
Thanks Enrique

B4J server. I'll get into it. So if we don't use B4J server, then nohup command, to run the application in the background, is not required. Am I right?
Since the site is working now with apache, I'll play with other options :)
Thanks.
 
Upvote 0

EnriqueGonzalez

Well-Known Member
Licensed User
B4J server. I'll get into it. So if we don't use B4J server, then nohup command, to run the application in the background, is not required. Am I right?
Yes that is correct.

I am confused on how you developed the app, if b4j is not required at all that means that you only created html files without server logic backing them.

Anyway, if later as you progress have any doubts, just ask
 
Upvote 0

oparra

Well-Known Member
Licensed User
Tips:

DNS only handles domain -> IP mapping. It cannot map the default port (80) to a custom port–you will have to use a reverse proxy for that. nginx is one of the most popular reverse proxies that are used to do that.

1. add a DNS record for your domain.

2. install nginx


3. Add a new server

server {
listen 80;
server_name mydomain.com;

location / {
proxy_pass http://localhost:8888;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

4. restart nginx

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/myapp
sudo service nginx configtest
sudo service nginx restart

5. test you domain http://mydomain.com

NOTE:
or you can use apache creating the virtual hosts for the domains
 
Last edited:
Upvote 0
Top