Setting up a virtual host in JBoss
Mon, 5 Sep 2005 10:05 PM GMT

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.

22 comments for Setting up a virtual host in JBoss
Migs
Tue, 6 Sep 2005 05:33 AM GMT

Nice documentation. It should be enough to undeploy jbossweb-tomcat.sar. No need to restart the entire JBoss.
Anonymous
Tue, 11 Oct 2005 11:42 PM GMT

Can you please provide some sample/example values/paths of the in the jboss-web.xml. Thanks and regards,
Dan Hinojosa
Wed, 12 Oct 2005 03:18 PM GMT

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

Lou
Thu, 20 Oct 2005 12:46 PM GMT

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?
Anonymous
Thu, 20 Oct 2005 10:59 PM GMT

I usually use Apache for the SSL certs.
Wesslan
Sat, 25 Feb 2006 08:27 AM GMT

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.xml
Maybe I should NOT have context-root in my jboss-web.xml at all?

Regards Wesslan
Danno
Sun, 26 Feb 2006 05:01 AM GMT

Really whatever you want them to say. It makes no difference.
Manish Kumar
Sun, 13 Nov 2005 08:55 AM GMT

Can we configure jboss and tomcat to work simultaneously with apache. if yes thwn plz mail me.
Sundeep Ramesh
Fri, 20 Jan 2006 07:44 AM GMT

could anyone tell me how to update the DNS Server
Steve
Tue, 31 Jan 2006 05:09 AM GMT

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?
Anonymous
Mon, 6 Mar 2006 02:47 AM GMT

Do we have to or should use Apache with jboss? thank you for your time viz
Danno
Mon, 6 Mar 2006 04:29 AM GMT

No it's optional
Ravi Kumar
Thu, 16 Mar 2006 04:54 AM GMT

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 java:/jaas/login TOPS/contextroot ravipartner.com server.xml ravipartner.com I am getting the following error. Forbidden You don't have permission to access ravipartner.com:8443 on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. -------------------------------------------------------------------------------- Apache/2.0.51 (Fedora) Server at ravipartner.com Port 8443 On my system is https is configured. Shall I need to modify my host configuration on my server.? The server is on Windows server. Can you help me in this regard. shall I need to do any additional configuration on my server.?
Anonymous
Wed, 3 May 2006 11:33 PM GMT

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
Anonymous
Tue, 20 Jun 2006 09:11 PM GMT

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
Anonymous
Fri, 11 Aug 2006 04:41 AM GMT

You need to tell jboss to listen on port 80 instead of 8080 by default (well tomcat to be specific), change server.xml
Diarmuid Leonard
Sun, 29 Oct 2006 08:07 PM GMT

In my case, the root cause of Tomcat error "No host matches server name" was that my ...... block was missing
Anonymous
Sat, 1 Sep 2007 02:43 AM GMT

null
Anonymous
Wed, 10 Oct 2007 12:56 AM GMT

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.
Anonymous
Mon, 29 Oct 2007 10:31 AM GMT

<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">&nbsp;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">&nbsp;</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 &nbsp;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>
David Costelloe
Fri, 7 Dec 2007 12:30 AM GMT

null
David Costelloe
Fri, 7 Dec 2007 12:33 AM GMT

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