After spending days trying to get it working, I felt kind of stupid after I learned how to have multiple domain names point to different web applications in my Jboss instances. I had read all of the documentation from the JBoss site and even some side blogs where people had set it up. However, as usual, the people writing these documents did so as people who have already done it and leave out key pieces of information, or fail to make subtle configuration changes clear.
Here we go, from scratch. I’ll give a simple sample scenario to make things easier.
You have one JBoss server running on your machine. You have two applications running under JBoss:
You also have registered two domain names:
You also have set up your DNS to have both domain names point to your server.
How do you get widgets.biz to point to widgets.war and thingamabobs.biz to point to thingamabobs.war? Let’s assume that you have widgets.war mapped as the root application and thingsmabobs.war mapped as thingamabobs.
widgets.war jboss-web.xml
———————————–
<jboss-web>
<context-root>/</context-root>
</jboss-web>
thingamabobs.war jboss-web.xml
———————————–
<jboss-web>
<context-root>/thingamabobs</context-root>
</jboss-web>
What you need to do is create a seperate Host configuration for the thingamabobs.war application in Tomcat’s server.xml file which is located at \jboss\server\default\deploy\jbossweb-tomcat55.sar\server.xml.
Open that file and you’ll see a Host configuration already for localhost. This is the default host meaning that all traffic directed via your web server port – which is 8080 by default, but I have mine set at 80 – will be directed to your root application. In our scenario, this is the widgets.war application.
Now let’s create a new Host designation that will direct requests for www.thingamabobs.biz to the thingamabobs.war application instead. Here’s what it would look like.
<Host name="thingies" autoDeploy="false" deployOnStartup="false" deployXML="false">
<Alias>www.thingamabobs.biz</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="things" suffix=".log" pattern="common"
directory="${jboss.server.home.dir}/log"/>
<DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>
The only things different about this Host entry is the name attribute and an additional Alias property. You can set the NAME attribute to whatever you like. The ALIAS property is the domain name that you want assigned to this Host designation. You can have multiple aliases per host. For example, if you want thigamabobs.widgets.biz to be redirected you could add that Alias in there as well (as long as you also set your DNS record for that domain as well).
We’re almost home and this is where the documentation wasn’t clear enough for me. The last step is to modify the jboss-web.xml file for thingamabobs.war. We’ve set up a brand new Host designation, so now thingamabobs.war can be set up as another root application, except now it sits in its own Host Space – called thingies – rather than in the one set up for localhost.
Here’s what the file should look like now.
<jboss-web>
<context-root>/</context-root>
<virtual-host>thingies</virtual-host>
</jboss-web>
You can see now that the new Host name we set up in Tomcat’s server.xml file – “thingies” – is the virtual host for the thingamabobs.war application, and it is now the root for that Host.
Now just restart your JBoss instance, and if your DNS changes have been made live, going to www.thingamabobs.biz will be redirected to the thingamabobs.war application, while www.widgets.biz will still be directed to the widgets.war application.
60 Responses for "Hosting Multiple Domains With JBoss"
I really impressed with this artical. But I am looking for running two different wars on seperate ports.
e.g. I have two wars app.war and run.war
if user requests for http://ipaddress:4011 it should redirect to app.war
and
if user requests for http://ipaddress:4012 it should redirect to run.war
context-root for both .war files will be /. How can I achieve this?
Abhijit, you would need to use Apache or IIS as a proxy to JBoss. I use Apache, and for your situation, you’d need to have the following configurations set up in your Apache configuration file.
First, you would tell Apache to listen on two ports:
Then set up two VirtualHost sections:
This will cause ports 4011 and 4012 to be redirected to JBoss – assuming you have JBoss running on port 8080 – where the Host designations will pick up.
Thanks Steve – you made this so much easier. Given that JBoss makes it’s money from professional services, the cynic in me can’t help but wonder if the difficulty in finding out how to do this isn’t some how part of the business model.
Thanks again!
Thank you Steve.
I have an issue which I was trying to sort out in the past couple of days with JBoss.
My Issue: suppose I want to access thingamabobs.war using IP and domain name,like the following :
1) http://www.thingamabobs.biz
2) http://127.0.0.1/thingamabobs (or http://127.0.0.1:8080/thingamabobs).
Has anybody clue how to sort this thing out ? I mean to mix the ip & domain name ?
please email me in case you can help me, my email address : zaidatheer@gmail.com.
Yours,
Zaid
Zaid, I sent you an email that describes how you would use a proxy to accomplish both the port forwarding and the URI rewriting necessary to accomplish this.
Hi Steve,
Many many thanks for the email :). I must say that you have some great skills in dealing with Apache configuration :).
Actually the rewriting idea is really good, however, I thought if there is a way to combine both IP and Domain name. Previously with Apache + Tomcat there was no problem in doing that, but with JBoss I dont’ know how to do that.
The purpose of using the IP + Domain name to access same web application is that to reduce the deployment process, means, I don’t need to change the jboss-web.xml every time I want to redeploy the project and vice versa, hence I can use either http://127.0.0.1/thingamabobs or http://www.thingamabobs.biz.
The big problem I guess is with the jboss-web.xml.
I would be appreciated if you or anybody can help me to configure JBoss so that I can access the web applications by either the IP or the Domain Name.
Thanks again Steve and kindest Regards
Zaid
I see what you’re asking now. You want to use JBoss, and JBoss only, to configure the server so that both of those URLs take you to thingamabobs.war.
Unfortunately, I don’t believe you can do this. Once you set up a virtual-host attribute in your jboss-web.xml file, you’ve tied it to a host (or multiple ones) and it no longer will be a subdirectory off of a host – in your case, localhost. Unless, of course, you specify a different context root, but all that does is make your app a subdirectory off of ALL hosts like this…
http://www.thingsmabobs.biz/thingamabobs
localhost:8080/thingamabobs
You said that with Apache+Tomcat, that it wasn’t a problem, and it still isn’t. Tomcat is the embedded web container inside of JBoss, but Apache functionality isn’t there by default.
You would need to install Apache on your server like I said in my email so that you can have an application work as a host and as a subdirectory.
Hi Steve,
Thank you again for the reply.
I feel like I didn’t explain my requirements in a simplified way, I will enumerate them like the following:
1. I want to Configure Apache + JBoss to use the virtual hosting.
2. I want to access the web applications using IP based + Domain-name based.
3. My main purpose of using IP based access is to avoid changing the jboss-web.xml every time I deploy the application.
Using rewriting will create a problem when I use it in the development machine, because if I used http://127.0.0.1/abc then it will redirect me to http://www.abc.com and thus the ip will change to 83.111.127.70 for example (which is the production machine, not the development)
Those following 2 links are referring to the same web application (Apache + Tomcat) and there was no problem at all, we can access it using IP-based and Domain Name-based:
http://83.111.127.70/googleTripsAtlas
http://www.almasalik.com
One more question, can I configure JBoss Virtual Hosting without using jboss-web.xml ?
Thank you Steve, hope to hearing from you.
Regads,
Zaid
A note about the the Host name attribute in server.xml:
It appears this should not contain capital letters – JBoss complains of duplicate hosts if this name contains any capital letters.
Hi Steve,
fantastic your article.
I need to change jboss’s welcome home page to my application.
When I request localhost:8080 I get Jboss Welcome Home Page. I need that request I get my welcome page application.
Can you help me?
Hi,
I went through your article. Its really nice to see the apache capable of doing all these things.
But, my requirement is bit different. I have two different applications hosted on JBoss, on 2 different ports. Lets take an example like:
http://myapp1:8080/
http://myapp2:18080/
Now, when I try to use the ‘Listen’ & ‘ProxyPass’ under Virtualhosts, it doesn’t work. Could you please tell me if I am missing something?
Muralidhar, could you provide some more information that might be helpful?
- Are either requests being redirected properly or are both failing?
- What does your Apache configuration look like (can you post your appropriate settings)?
- Are the two JBoss server configured to serve on those two ports (8080 and 18080)?
- Can you describe what is happening when you try both URLs? Error codes?
Steve, great article about using JBoss to host multiple domains. I had a question about multiple domains and Apache and JBoss. I would like to have Apache be able to handle request for multiple domains. I would like to be able to have multiple domains go to different JBoss contexts. An example being:
http://www.domain1.com goes to http://jboss_ip:8080/domain1
http://www.domain2.com goes to http://jboss_ip:8080/domain2
I was looking at mod_proxy as a solution, but wanted to leave myself open to using SSL later on. Does this mean I should be using mod_jk? Have you tried implementing a solution similar before?
Hi Steve,
I impressed with your suggestions on domains configuration to all.
I have deployed an imsproject.ear file into jboss4.0.3 server and context root is ims.
i want to access this application through http://www.ims.com, what shall i do.
can you help me out
Regards
Mahendra
John, I’ve only used mod_proxy for handling multiple domains going to different contexts. I’ve never had to use SSL on those domains so I’m not aware of those restrictions.
Mahendra, you’ll have to use IIS or Apache as a proxy to JBoss. Investigate mod_proxy in Apache. It’s an easy installation and far easier to configure than IIS.
[...] For more advanced configurations of JBoss, here are some links to other relevant posts. Running multiple ColdFusion instances Securing your JBoss web applications Hosting multiple domains in JBoss Flexible ColdFusion deployment – serving from anywhere [...]
I have configured my jboss to run on SSL. I want that whenever someone hits server on http(port 80), the request should be redirected to https{port 443). Is it possible? If yes, how?
Hi Steve,
I need to change jboss’s welcome home page to my application.
When I request localhost:8080 I get Jboss Welcome Home Page. I need that request I get my welcome page application.
You might have already recieve this mail before from Marcos, i too have the same doubt, but i couldn’t find any answer beeing posted in this.
Further i have two application to be hosted in in One Single JBoss AS.
Can u further explain on virtual hosts???
Thanking u in advance…
Geen
Hi Steve,
fantastic your article.
I have a Jboss AS and web appliction ,it’s work but the problem is :
when i run my application from localhost i write(http://localhost:8080/app)and it’s work oky.
but from out i write (www.app.com) it’s not work,
must follwed by (/app) to work for example(www.app.com/app).
but i was searched in internet and i must use mod_
proxy.
Can you tell me how i solve this problem with mod_proxy
thanks for help me.
Mohannad Alsadi
Mohannad, please read this article again as it explains how to do what you are asking.
Focus on the context-root attribute in your jboss-web.xml file.
Hi Steve,
I have 2 war files suppose abc.war and xyz.war
I want to run abc.war on http and xyz.war on https…
How can I configure my JBOSS to do the same…
Please reply.
Rashmit
Rashmit, I’m sorry I can’t help you on that one. I haven’t delved into HTTPS on JBoss yet.
Hi Steve,
It looks like you’re trying to do the opposite of what I need to do, but I’ll ask the question anyway…
I’d like to have two .WARs sitting in a sever in JBoss (we’ll call it “foo” for originality’s sake), the first one exploded for working with static content (css/images/javascript/etc.), the second one would be archived containing the dynamic content (JSPs and the like), sort of like the following:
\jboss\server\foo\deploy\static.war
\jboss\server\foo\deploy\dynamic.war
…and I’d like to be able to pull the static content from pages in the dynamic war. For some reason, however, it’s not working the way I expected, and images/css are not being found.
So I figure it must be something similar (i.e. configuration issue), but I know next-to-nothing about configuring jboss/tomcat/apache.
Any chance you’d know how to get this working the way I’d like it to? If not, that’s OK – I just thought I’d ask. :)
Thanks!
-evan
Hi Steve
I’m having trouble trying to implement this article in my application. The story is the same I want apache to redirect request to JBoss. I have set up apache to listen on 127.0.0.1:4011 and also set up
the virtual host as follows
ServerName http://localhost/Matrix
ProxyPass / http://locahost:8080/MatrixPOC/MatrixServlet
but im unable to get this working. My understanding requires that i just configure apache and not JBoss because i just want apache to redirect and JBoss function as per normal http request.
What am i doing wrong?
Please help.
Dylan
Evan, so you’re trying to link content that’s located in dynamic.war from another file inside static.war?
Dylan, is there a reason you’re telling Apache to listen to port 4011?
Also, you’re using the ServerName directive wrong. Read the Apache docs on its usage.
If you just want to redirect all traffic on port 80 over to JBoss, just have Apache listen on port 80 and use ProxyPass for each domain.
Listen 12.34.56.78:80
NameVirtualHost 12.34.56.78:80
<VirtualHost 12.34.56.78:80>
ServerName http://www.domain.com
ProxyPass / http://www.domain.com:8080/
LogFormat combined
</VirtualHost>
<VirtualHost 12.34.56.78:80>
ServerName http://www.domain2.com
ProxyPass / http://www.domain2.com:8080/
LogFormat combined
</VirtualHost>
Hi Steve
Thanks for the reply.
I tell Apache to listen on a different port because I cant allow all incoming traffic to be redirected to JBoss only when a certain URL is hit say for instance http://localhost.co.za:4011/AppName
then the request must be redirected to JBoss.
Thanks
Dylan
Ok, Dylan, then these would be the settings you need.
Listen 12.34.56.78:4011
NameVirtualHost 12.34.56.78:4011
<VirtualHost 12.34.56.78:4011>
ServerName localhost.co.za
ProxyPass /Matrix http://localhost.co.za:8080/MatrixPOC/MatrixServlet
</VirtualHost>
Many Thanks Steve.
I am also using jboss-4.0.2 but i am not able to set DocumentRoot in httpd.conf of Apache2. Could any on let me know to which directory it should set. I am having sugarmite.war in jboss deploy directory.
This is great information.
I was able to get to this work with two hosts on the same server. I created two new Host entries in the server.xml file, with aliases with and without the www prefix.
I deployed both applications as EAR files and had to modify the application.xml in the ear/META-INF directory to empty the paramater for my default war deployment in order to make the context work.
Hai Steve,
Fantastic article!
My Question is, if i’m using Joomla as my portal and Jboss as my server, and I have registration form(JSP) on Jboss server. How can i link from Joomla (user click registration button) to registration form? Is there any configuration?
@ladylike2paint. I hope someone can help you out on that one. I have no idea. Sorry.
Hello Steve,
I went through all the posts above. But my problem is a bit different. I have an application say app.ear or app.war deployed on JBoss. I can access this application from the same machine using the localhost link. But if I want to access this same application from another PC, I am trying to replace the localhost with the IP address of the machine. But in this case, I get page cannot found error. I tried with the PC name too in the link. But that also does not help me. So I am wondering, where do I do this setting. I am using JBoss 4.2.1.
Thanks,
Nikhil.
Hi Steve,
I have an issue which I was trying to sort out in the past couple of days with JBoss3.2.3(with embedded tomcat4.1 as default webserver).
My Issue: Two different applications(Ex: thingamabobs.war and bobs.war ) are running in the single JBoss instance and it’s listening to port value 8080.
suppose
1)I want to access thingamabobs.war using IP and domain name,like http://www.thingamabobs.com (or http://127.0.0.1:8080/).
2)I want to access bobs.war using IP and domain name,like http://www.thingamabobs.com/bobs (or http://127.0.0.1:8080/bobs).
Has anybody clue how to sort this thing out ?
please email me in case you can help me, my email address : anm.gopi@gmail.com.
Yours,
Gopal.
Hello steve
I have jboss 4.2 server installed and the HTTPS is enabled and running in port 8090 ,i have two IP’s to my system ,with different domain mapped to it say https://xxx.com and https://yyy.com,when i access the server locally both domains are working, but when accessed outside the system only one is working,Do i need to do any configurations in JBoss to make it work on both domains
Steve,
I need your help to solve an issue.
I have an EAR ptrack.ear deployed in JBoss 4.0.4.
I was able to run my application ,a DNS name was created for the same as ‘ptrack.tajtech.com’
Now,I can access my application as http://ptrack.tajtech.com/PtrackWeb/login/ListPageListRefresh.do
My requirement is tht when the DNS name is typed i shud get the login page.
Is Apache server is needed for the same?If so how to install the same.
Not trying to use more than 1 domain name,but for 1 domain name wish to know the steps to be followed to invoke my application.
Kindly ,can you mail me the steps ASAP to anitha.mca@gmail.com.
Thanks in Advance
Hi Steve,
I have two war files under my deployment directory to server two web applications. I have same port and same IP for both. My Jboss is using apache at the front.
I can easily start and stop the whole jboss, but how can i start and stop a particular war file through command line.
Thanks
KD
Hi Nikhil
u need to run JBoss by giving the command :
run -b ipaddress
Thanks
VJ
Hi Steave,
I was just going thru this blog and found one interesting question ( to me atleast ) asked to you long back. Below it is. I also have similar requirement but could not find any clues in the blogs. Do you pls let me know any links where in I can achieve this???
>>>>>>>>>>>>>>>>>>>>>>>
#
evan on February 13th, 2007
Hi Steve,
It looks like you’re trying to do the opposite of what I need to do, but I’ll ask the question anyway…
I’d like to have two .WARs sitting in a sever in JBoss (we’ll call it “foo” for originality’s sake), the first one exploded for working with static content (css/images/javascript/etc.), the second one would be archived containing the dynamic content (JSPs and the like), sort of like the following:
\jboss\server\foo\deploy\static.war
\jboss\server\foo\deploy\dynamic.war
…and I’d like to be able to pull the static content from pages in the dynamic war. For some reason, however, it’s not working the way I expected, and images/css are not being found.
So I figure it must be something similar (i.e. configuration issue), but I know next-to-nothing about configuring jboss/tomcat/apache.
Any chance you’d know how to get this working the way I’d like it to? If not, that’s OK – I just thought I’d ask. :)
Thanks!
-evan
>>>>>>>>>>>>>>>>
-Jts
try using this for http to https, works for me
my jboss is using ssl.
ServerName xyz.com
RewriteEngine On
RewriteRule ^(.*)$ https://xyz.com:$1
ServerName abc.com
RewriteEngine On
RewriteRule ^(.*)$ https://abc.com:$1
RewriteRule ^(.*)$ https://xyz.com:portNo$1
it didn’t show portNo in prev comment
I want to run my applications using something like: http//www.mysite.com:8080/app_name/jsp_name.jsp
and NOT like: http://localhost:8080/app_name/jsp_name.jsp
i.e i want to REPLACE “localhost” with “www.mysite.com”
Also, how do I change the port number?
Thanks.
u can change the port number in jboss-service.xml file located in conf folder
Thanks
VJ
if ur using solaris u can change ‘localhost’ to your domain name ‘www.mysite.com’ by editing the server machine host file by setting :
ip number domain name
e.g.
192.168.1.1 http://www.mysite.com
for solaris the host file is /etc/hosts
for windows xp, the host file is C:\WINDOWS\system32\drivers\etc
examples are already given in the file itself
My application URL is different and i want to change to different .
How we do so
Regard abhishek
Hi,
this is very good article on multiple domains set-up on JBoss.
I am using Apache and mod_jk to connect to JBoss.
I’m not really sure how to deal with this matter because I seems to use the same WAR over and over again – however I try to remake the config.
I’ve posted my question here:
http://www.jboss.com/index.html?module=bb&op=viewtopic&t=127907&start=0
You seem to be the right guy to answer my questions. (I’ve solved the filter part)
Many thanx,
/Frippe
Hi,
I have an issue which I have been trying to solve with JBoss4.0.4-GA but hadn’t any success so far.
I have my web application myapp.war and web services running in the single JBoss instance.
1)I would like anyone to be able to access the web application myapp.war using url https://myhost:8443/myapp without any client authentication.
2)But I would like to put the web services on port 8444 and turn on client Authentication on that port so that people with a valid certificate only can access the web services using URL https://myhost:8444/jbossws/.
I have added connectors for ports 8443 with clientAuth=false and 8444 with clientAuth=true. Can anyone suggest me how to disable jbossws on port 8443 and how to disable myapp on 8444? Any help would be appreciated.
Please email me in case you can help me, my email address : anne_poornima@yahoo.com.
Thanks,
Poornima
I have failed to call my axis2 web service(i have axis2 in jboss 4.2.1) when i use the ip address istead of localhost..can u plz tell me what i have to do to make it work??
Thanks, works brilliantly
Thankyou!!!!
Managed to connect apache to JBoss using mod_jk but could get the urls to work properly
eg http://app wouldn’t work but http://host/app would
After two days of searching found your site and fixed my problem
Should consider adding to the site an explanation of the config for the apache2 uriworkermap.properties as well, for users that are using mod_jk, as so far you seem to be the only referentce that explains how to get this stuff set up right as represents the next step if users are putting JBoss behind apache
Hi steve,
I have installed two different wars lets say x1.war and x2.war. in x1 war file created one servlet which basically uses classes from specific jar file which exists (same jar) in x2.war. In this case i am getting error for retrieving naming context but if i remove specific jar from x1.jar then it works fine and that servlet which lies in x1.jar uses x2.war’s jars. But i dont want to make such dependency. In future suppose i will remove x2.war then it wont work so please guide me on this. Please reply me on vpvaidya@gmail.com.
Thanks
Vishal
Hi Steve,
I am new to jboss application server.
I have an issue which I have been trying to solve with JBoss4.2.3-GA but hadn’t any success so far.
I have my web application myapp.war running in the single JBoss instance.when I access the application using http://localhost:8080/myapp, it works fine.But I’m not able to access the application remotly using my machine’s domain name or IP. Kindly help me in solving this issue.
Thanks in advance.
Shijo
Hi,
Kindly tell me that is there any way to have two context names of the same web application.. like http://www.abc.com/admin/login.html and similarly we have http://www.abc.com/client/login.html ?
Regards
Jaffy, the URLs you want do not need to be separate contexts. The ‘admin’ and ‘client’ folders would simply be sub-folders of your abc.com application.
Hi Steve,
This is fantastic…
It will be very helpfull if you throw some light on how can I serve static direcories(source) through web without adding tag in server.xml, or copying/mounting the source inside ROOT.war.
Any idea will help me a lot.
Thanks in Advance
Rajiv
Thanks for your help,
Pankaj patel
Hi, first, nice info around here. gratz.!
second:
I have one application like “create you own site” it´s alwasy the same application but id´like to cross reference between domains and the application.
for example:
http://www.site1.com renders the application containing the “site1″ client info.
http://www.site2.com render the application containing th “site2″ client info.
Any thoughts or ideas?
tks !
Hi Steve, I am working in JBOSS 4.2.3. I have sam1.war file in my project ear file. I need to add one more war file sam2.war. This sam2.war file contains flash files only. I need to access these flash files from readFlash.xhtml which is in sam1.war file. How to do this? The context.root for both war files should be same. Do I need to configure anything to do this. I dont know how to proceed. Please help me in this regard.
[...] Hosting Multiple Domains With JBoss [...]
Leave a reply