6 Replies Latest reply on Feb 6, 2017 9:00 AM by Tomaz Cerar

    Undertow - Point a subdomain at a virtual host

    andy56_uk Newbie

      Hi,

       

      I currently have two domains, for example maindomain.com and productdomain.net.

       

      maindomain.com, productdomain.net, and all sub-domains are pointed at the same server (eg: 11.22.33.44) which is running WildFly 8.1 Final.

       

      In summary, what I want to achieve is something like this:-

       

      maindomain.com -> website.war

      other.maindomain.com -> otherwebsite.war

      productdomain.net -> product.war

      demo.productdomain.net -> productdemo.war

       

      Anyone pointing their browser at maindomain.com sees our company web site, as intended.  I have added default-web-module="website.war" to the default-host specification in standalone.xml to achieve this.

       

      Currently, anyone pointing their browser at productdomain.net or any sub-domain is also seeing our company web site, but I want them to see a different application (eg: productdemo.war).  I've searched this forum and Google, and I've tried adding various host/server entries in standalone.xml but can't figure out how to set up a virtual host in Undertow that will filter on the host header (eg: demo.productdomain.net).

       

      Can anyone tell me how I need to set up Undertow to do this please?

       

      Many thanks,

       

      Andy

        • 1. Re: Undertow - Point a subdomain at a virtual host
          Tomaz Cerar Master

          Hi,

           

          just add another <host name="name-of-other-host" alias="my.other.domain, second.tld">

          element and which has extra alias(es) that you want

          you can also add default-web-module="my-other.war" and that will be it.

           

          <host name="name-of-other-host" alias="other.maindomain.com" default-web-module="otherwebsite.war" />

          <host name="product" alias="productdomain.net" default-web-module="product.war" />

          etc

           

          for more advanced mapping from your war to virtual host, you can add jboss-web.xml to your WEB-INF

           

          with contents like:

           

          <?xml version="1.0" encoding="UTF-8"?>

          <jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"

                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                     xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/schema/jbossas/jboss-web_8_0.xsd"

                     version="7.1">

              <context-root>/</context-root>

              <virtual-host>context-host</virtual-host>

          </jboss-web>

          • 2. Re: Re: Undertow - Point a subdomain at a virtual host
            andy56_uk Newbie

            Hi Tomaz,

             

            Thanks for taking the time to help with this.

             

            I had already found your first suggestion in a reply that you had made to another user, but it doesn't work for me.

             

            In standalone.xml I have:-

             

            <server name="default-server">
              <http-listener name="default" socket-binding="http"/>
              <host name="default-host" alias="webapp.maindomain.com" default-web-module="website.war"/>
              <host name="product-host" alias="test.productdomain.net" default-web-module="product.war"/>
            </server>
            
            

             

            On the name server for maindomain.com I have the following A record:-

            Subdomain = webapp

            Address = <ip_address_of_wildfly_server>

             

            On the name server for productdomain.com I have the following A record:-

            Subdomain = test

            Address = <ip_address_of_wildfly_server>

             

             

            Pointing a browser at webapp.maindomain.com results in website.war being called as expected, but pointing a browser at test.productdomain.net also results in website.war being called - I was expecting product.war to be called.

             

            Both applications are deployed and enabled on the WildFly server, and if I point my browser at webapp.maindomain.com/product or test.productdomain.net/product then product.war is called.

             

            In order to try your second suggestion of adding a jboss-web.xml file to WEB-INF, what values should I use in the following fields for the two sub-domains?

             

            <context-root>/</context-root> 
            <virtual-host>context-host</virtual-host>
            

             

            Many thanks,

             

            Andy

            • 3. Re: Re: Undertow - Point a subdomain at a virtual host
              andy56_uk Newbie

              HI,

               

              Can anyone offer any advice on how to get this working with Undertow please?

               

              Failing that, is it possible to use WildFly with Apache Web Server instead of Undertow?

               

              Thanks,

               

              Andy

              • 4. Re: Undertow - Point a subdomain at a virtual host
                andy56_uk Newbie

                After further investigation I've found that switching the 'name' value of the <host .../> elements as follows results in product.war being called whichever URL is used:-


                <host name="product-host" alias="webapp.maindomain.com" default-web-module="website.war"/> 

                <host name="default-host" alias="test.productdomain.net" default-web-module="product.war"/>

                 

                It looks like Undertow is only processing details of the "default-host" entry.

                 

                Any suggestions please?

                 

                Andrew

                • 5. Re: Undertow - Point a subdomain at a virtual host
                  Eric Austman Newbie

                  Hi Andrew,

                   

                  I'm running into the same issue on Wildfly10.1.  I can't seem to get a 2nd host to work.  Did you ever get this working and have any suggestions?

                   

                  Thanks,

                  Eric

                  • 6. Re: Undertow - Point a subdomain at a virtual host
                    Tomaz Cerar Master

                    Eric Austman wrote:

                     

                    Hi Andrew,

                     

                    I'm running into the same issue on Wildfly10.1. I can't seem to get a 2nd host to work. Did you ever get this working and have any suggestions?

                     

                    Thanks,

                    Eric

                    It will work just fine if you add jboss-web.xml as described.

                     

                    OOTB solution that would take default-web-module attribute is fixed in master and will be part of WildFly 11