Setting up a virtual host in JBoss
Filed Under: server.xmlApachemod-jk.confhttpd.confVirtualHostJ2EEJBossVirtualHosts
A few days ago, I set up a virtual host on my server using JBoss/Tomcat with an Apache front-end. It was pretty simple. First thing is that I edited the server.xml document located in the tomcat sar directory in the deploy directory of your favorite server (minimal, default, or all). When I refer to the tomcat sar I am referring to the sar directory that houses all tomcat information. On my current server (JBoss-4.0.2), the sar directory is called jbossweb-tomcat55.sar
In the server.xml file you will see something similar to the following...
<Server>
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<!-- A HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" address="${jboss.bind.address}" .../>
<!-- A AJP 1.3 Connector on port 8009 -->
<Connector port="8009" address="${jboss.bind.address}" .../>
<!-- SSL/TLS Connector configuration using the admin devl guide keystore
<Connector port="8443" address="${jboss.bind.address}" .../>
<Engine name="jboss.web" defaultHost="localhost">
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
....
</Host>
<!--Here is where you will set up your hosts -->
</Engine>
</Service>
</Server>
Inside the engine element is where you will set up your hosts configuration. Currently there is a host set up for localhost. What needs to be done is that there needs to be a sibling to localhost set up for your new virtual host.
<Server>
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<!-- A HTTP/1.1 Connector on port 8080 -->
<Connector port="8080" address="${jboss.bind.address}" .../>
<!-- A AJP 1.3 Connector on port 8009 -->
<Connector port="8009" address="${jboss.bind.address}" .../>
<!-- SSL/TLS Connector configuration using the admin devl guide keystore
<Connector port="8443" address="${jboss.bind.address}" .../>
<Engine name="jboss.web" defaultHost="localhost">
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
....
</Host>
<Host name="virtualhost2" autoDeploy="false"
deployOnStartup="false"
deployXML="false">
<!-- Add all your aliases here -->
<Alias>virtual.evolutionnext.com</Alias>
<Alias>myvirtual.evolutionnext.com</Alias>
<!-- Set up logging -->
<Valve className="org.apache.catalina.valves.AccessLogValue" prefix="virtualhost2" suffix=".log" pattern="common" directory="${jboss.server.home.dir}/log"/>
<DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>
</Engine>
</Service>
</Server>
Restart the JBoss server and your JBoss server is ready to host a new subhost. Remember to update your DNS servers! Unfortunately the simplest things are the hardest to figure out, and it took me a while to figure out to update my DNS server.
If you are using Apache as a front end. What I did is modify my mod-jk.conf to let all traffic through to JBoss and let jboss take care of the virtual hosting. There is a sample of my mod-jk.conf below. Before doing this the easy way, I was trying to set up a virtual through httpd.conf and that seemed to have been fruitless and aggravating. You should probably know already by now how torturous it is to edit the httpd.conf file. I think you will find it a pleasure to let JBoss handle all J2EE virtual hosting.
# Load mod_jk module # Specify the filename of the mod_jk lib LoadModule jk_module modules/mod_jk.so # Where to find workers.properties JkWorkersFile conf/workers.properties # Where to put jk logs JkLogFile logs/mod_jk.log # Set the jk log level [debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" # JkRequestLogFormat JkRequestLogFormat "%w %V %T" # Mount your applications JkMount /* mainWorker
Notice my JkMount is letting all traffic through. If I have something else specific that I need apache to care of I provide an explicit path in my httpd.conf directory. That would usually be non-J2EE services like Subversion for example.
The last thing that is needed, is to adjust your webapp. If, in your war file you do not have a jboss-web.xml file in your WEB-INF directory, create one, and put in the following. If you are updating yours, then make sure that it has the following elements...
<jboss-web> <context-root>/</context-root> <!--Make what ever context root you want --> <virtual-host>virtual.evolutionnext.com</virtual-host> </jboss-web>
This will route traffic to the Alias mapped in your server.xml file. Now, try to go to your new subhosted website and it should work like a champ. If it doesn't, post me a comment.
Tue, 11 Oct 2005 04:42 PM PDT
Can you please provide some sample/example values/paths of the
Wed, 12 Oct 2005 08:18 AM PDT
Something like this is all you need. You can change your context root to whatever you would like. In the virtual host tag you need to give it a value of what you want your server name to be.
/ virtual.evolutionnext.com
Thu, 20 Oct 2005 05:46 AM PDT
I have follwing env: -apache2 with few virtual hosts defined (one is defined to work over ssl) -mod_jk2 configuration to work with 2 JBoss containers (their tomcats in fact) -2 jboss identical containers contain few j2ee web app (same apps in both) The problem is I'm not able to make one of those j2ee web app to work with ssl. They all work ok with http but not with https. Should I change something in jboss configs, or it should all have to do with apache?
Thu, 20 Oct 2005 03:59 PM PDT
I usually use Apache for the SSL certs.
Sat, 25 Feb 2006 12:27 AM PST
If I have the war's in (separate) ear's, what should context-root say in:
ear1/META-INF/application.xml ear1/war1/WEB-INF/jboss-web.xml ear2/META-INF/application.xml ear2/war2/WEB-INF/jboss-web.xmlMaybe I should NOT have context-root in my jboss-web.xml at all?
Regards Wesslan
Sat, 25 Feb 2006 09:01 PM PST
Really whatever you want them to say. It makes no difference.
Sun, 13 Nov 2005 12:55 AM PST
Can we configure jboss and tomcat to work simultaneously with apache. if yes thwn plz mail me.
Thu, 19 Jan 2006 11:44 PM PST
could anyone tell me how to update the DNS Server
Mon, 30 Jan 2006 09:09 PM PST
Is Apache required to allow virtual hosts. I have followed your example (and also the one from JBoss) and I get this response when I set up this configuration. HTTP/1.1 400 No Host matches server name vhost.mydomain.com I run my own DNS server and added vhost.mydomain.com to its records, so I know that's up and running. Ideas?
Sun, 5 Mar 2006 06:47 PM PST
Do we have to or should use Apache with jboss? thank you for your time viz
Sun, 5 Mar 2006 08:29 PM PST
No it's optional
Wed, 15 Mar 2006 08:54 PM PST
Hi, I set up a virtual host in my JBOSS 4.0.2 Server with the following configuration of jboss-web.xml and server.xml and calling the following URL. https://ravipartner.com:8443/TOPS/contextroot/login.do jboss-web.xml
Wed, 3 May 2006 04:33 PM PDT
how to set vitual host to my site i am developed using jsp ans servlets i don't to how to redirect the server to my war file can some one help me
Tue, 20 Jun 2006 02:11 PM PDT
Hi all, Has anybody managed to host with jboss without Apache? I've tried every single possiblitly on winxp: the dns server is redirecting to my machine; the virtual host is deployed and when I test it, jboss is completely unware of any connection. Thank you for any suggestion
Thu, 10 Aug 2006 09:41 PM PDT
You need to tell jboss to listen on port 80 instead of 8080 by default (well tomcat to be specific), change server.xml
Sun, 29 Oct 2006 12:07 PM PST
In my case, the root cause of Tomcat error "No host matches server name" was that my
Fri, 31 Aug 2007 07:43 PM PDT
null
Tue, 9 Oct 2007 05:56 PM PDT
Hi,
Can you please provide some inputs as how i need to setup virtual host if iam using jboss 3.2.1. I tried the suggested method as done in jboss 4.0.2 but was not successful. Any pointers helping me to solve the problem is highly appreciated.
Thanks.
Mon, 29 Oct 2007 03:31 AM PDT
<div><u><font color="#000080" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy">Problem faced:</span></font></u></div> <div><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">My application is currently accessed as <a title="http://ptrack.tajtech.com/PtrackWeb/login/ListPageListRefresh.do" href="http://ptrack.tajtech.com/PtrackWeb/login/ListPageListRefresh.do"><font title="http://ptrack.tajtech.com/PtrackWeb/login/ListPageListRefresh.do" color="#333399"><span title="http://ptrack.tajtech.com/PtrackWeb/login/ListPageListRefresh.do" style="COLOR: #333399">http://ptrack.tajtech.com/PtrackWeb/login/ListPageListRefresh.do</span></font></span></font></div> <div><font color="#333399" size="2"> </font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">But when user keys-in <a title="http://ptrack.tajtech.com/" href="http://ptrack.tajtech.com"><font title="http://ptrack.tajtech.com/" color="#333399"><span title="http://ptrack.tajtech.com/" style="COLOR: #333399">http://ptrack.tajtech.com</span></font> ,he should be directly able to access the login page </span></font><font color="#000080" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy">,</span></font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">without</span></font><font color="#000080" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy"> the necessity </span></font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399"> giving the full link.</span></font></div> <div><font color="#333399" size="2"> </font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">Hope you got my requirement.</span></font></div> <div><font color="#333399" size="2"> </font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">My application is deployed in JBoss4.0.4</span></font><font color="#000080" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy">.</span></font></div> <div><font color="#333399" size="2"> </font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">Please find attachment of server.xml and jboss-web.xml for this application</span></font><font color="#000080" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy"> which I have edited after some self study to meet the requirement</span></font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">.</span></font></div> <div><font color="#333399" size="2"> </font><font color="#333399" size="2"> </font><font color="#000080" size="2"><span style="FONT-SIZE: 10pt; COLOR: navy">p</span></font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">track.tajtech.com is the DNS name created for our application.</span></font></div> <div><font color="#333399" size="2"> </font><font color="#333399" size="2"><span style="FONT-SIZE: 10pt; COLOR: #333399">Kindly, help me out to solve this issue.</span></font></div>
Thu, 6 Dec 2007 04:30 PM PST
null
Thu, 6 Dec 2007 04:33 PM PST
Hi, Could you please provide a sample using Jboss 4 (Latest) to have the Default portal go to the domain name?
http;//www.mydomain.com loads the Default portal. So far I have only been able to load the Jboss application server with my domain.
Appreciated
Thanks
Mon, 5 Sep 2005 10:33 PM PDT
Nice documentation. It should be enough to undeploy jbossweb-tomcat.sar. No need to restart the entire JBoss.