Virtual hosting with Jboss 5.1

How do I map a web application to a url in jboss?

If you have multiple web apps deployed in a single jboss instance, you’ll probably want to figure out an effective way to tell them apart when you try to access them from a browser. On startup jboss can be configured to bind to a single url which will act as the default host for all the deployed applications. You can then set up a separate context for each web app you are running. If they’re totally separate applications though, it might not make sense to use a single url and break them out by context. In Jboss you can set up virtual hosts to solve this dilemma. Here’s how to set this up:


In your web application you’ll want to add an xml file named “jboss-web.xml” to your WEB-INF folder. This is the file that’s going to map both the web application’s context and host in jboss.


This configuration sets the application’s context to “/” (essentially the root of the default domain), and it also maps the virtual host configuration to “”. Note that it wont matter if you deploy this configuration from within an ear (embedded war file) or as a standalone war file, as only wars are meant to respond to web requests. Let’s also add the second configuration to the other war file’s WEB-INF/jboss-web.xml:


Next, we’ll need to add the virtual host configurations to jboss’ server.xml.


Now we need to edit jboss’ server.xml file, adding the virtual host mappings:

   <Service name="jboss.web"
      <!-- A HTTP/1.1 Connector on port 8080 -->
      <Connector port="8080" address="${jboss.bind.address}"
                 maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
                 enableLookups="false" redirectPort="8443" acceptCount="100"
                 connectionTimeout="20000" disableUploadTimeout="true"/>

      <Engine name="jboss.web" defaultHost="">
         <Realm className=""
         <Logger className="org.jboss.web.tomcat.Log4jLogger"

            <Host name="" autoDeploy="false"
                  deployOnStartup="false" deployXML="false">
                <Valve className="org.apache.catalina.valves.AccessLogValve"
					   resolveHosts="false" />

            <Host name="" autoDeploy="false" 
                  deployOnStartup="false" deployXML="false">

                <Valve className="org.apache.catalina.valves.AccessLogValve"
					   resolveHosts="false" />


Note the alias map other optional domains that jboss would listen for as aliases of the keyed domains “” and “”. All this means is jboss will redirect requests for processing to the respective web application’s whose virtual-host config maps to this host configs.

In order for all of this to work however, we need to make sure dns is set up to handle these domain requests. On a local development machine, you’ll want to edit your hosts file (on windows: c:/WINDOWS/System32/drivers/etc/hosts, on linux: /etc/hosts) and add these entries:

This way when you type in one of the domains into your browser, it’ll forward the request to jboss’ bound IP. likewise, if you have jboss bound to a specific domain name/IP on boot, you would have to map that domain/ip in your hosts file just like in the example above.

Now you should be able to fire up jboss, type in either domain into the browser, and have jboss redirect those requests to the corresponding deployed war file.

Comments (12)

  1. 3:16 AM, June 18, 2010saujana  / Reply

    hi Ant,
    could you help me with the ip based virtual host configuration?
    is the steps similar to what you’ve shown ?
    what i tried to do is
    a.a.a.a will point the the web app a.war
    b.b.b.b will point to the web app b.war
    but the this is so far a.a.a.a can also view the web app b.war

    i really appreciate if you can help me out since im just started to use jboss

    • 10:23 PM, June 19, 2010Ant  / Reply

      Hi Saujana,
      Binding IPs is problematic as the IPs are usually bound to the machine’s network card and are not usually used to mark individual applications. Domains are used more frequently for this purpose. The problem stems from jboss binding to only one IP or domain on startup. Well, thats how I’ve usually done thing. Although, if you don’t bind jboss to an IP or domain on startup it should then listen on all IPs bound to it. So maybe if you don’t give it an address to bind, and then assign those IPs in the host configs and in the jboss-web.xml to match, that might get you what you’re looking to do. You’ll need to set up those ip aliases on the network card too but I’m assuming that’s already set up.

      Good Luck

  2. 11:29 PM, June 20, 2010saujana  / Reply

    good morning Ant,
    thanks a lot for the answer
    it’s really helpful


  3. 5:04 AM, July 23, 2010anandan  / Reply

    It is very useful for me. they given example code also very useful for me. i am really thank u for pulblish this code here.

  4. 4:27 PM, October 30, 2010Mister Woody  / Reply

    Nice post thanks. One query though – should the host file settings be rather than


    • 10:19 PM, November 1, 2010Ant  / Reply

      Indeed, thanks for catching that.

  5. 9:21 AM, September 9, 2011Samer Gad  / Reply

    Hi Ant,

    First, sorry for replying on an old post, but it was very useful and I still want to ask for a further detail. How can I change the code-base for a specific virtual host?

    Best Regards,

    • 9:37 AM, September 9, 2011Ant  / Reply

      I’m not sure what you mean by changing the code base for a specific virtual host? Do you have multiple wars, multiple domains, or both? What are you trying to do?

  6. 11:19 AM, December 9, 2011genci  / Reply

    I am new to this, so I would really appreciate your help. I have deployed a third party tool using jboss. I can access the site using https://localhost:8443/index.html. Instead of localhost:8443 I would like users to enter (for example). I did try your suggestion, but can’t get it to work. Any suggestions?


    • 1:11 AM, January 4, 2012Ant  / Reply

      Assuming you’re using jboss 5.1, if you’re accessing jboss through 8443 then you’re accessing the alternate https port. Check your /jboss-5.1.0/server/standard/deploy/jbossweb.sar/server.xml file and make sure this section of the xml file is not commented out:

      If it’s not commented out, and you can access your site off port http://localhost:8080/index.html, then you can just change this port number from 8080 to 80. Ideally you won’t have jboss serving up any static content if you are running a large site. In those setups you’ll want to run something like apache to serve up your static content and then have it redirect dynamic content to jboss for processing. For smaller sites, this isn’t much of a big deal but it never hurts to be efficient.

      Good luck

  7. 1:16 PM, October 1, 2012Justin  / Reply

    I have the following problem:

    We have installed Software Quality Center by HP which is been installed on Joss server both as application and web servers.

    To access the start page I want instead of:


    I want to access like https://qc

    Could you please let me know what changes i need to male. I tried the above steps it is not working

    Best regard in advance

    • 11:33 AM, October 11, 2012Ant  / Reply

      you basically want to serve up your qc site with a web server like apache on the front end, and Install mod_jk. You can then set up an apache virtual host that points to the url: https://abcd:8443/qcbin/ and have https://qc as an alias. On the jboss side you will need to make sure the instance is listening for the mapped domain. Putting these two pieces together will get you what you’re looking for.

Leave a Reply

Allowed Tags - You may use these HTML tags and attributes in your comment.

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Pingbacks (0)

› No pingbacks yet.