1 2 Previous Next 16 Replies Latest reply on Sep 7, 2012 3:57 AM by mr-678

    Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)

    mr-678

      I try to use virtual-server like descriped in the wiki (https://community.jboss.org/wiki/VirtualHostsWithJBossAS7)

      One JBoassAS 7 for several domains (www.mydomain1.de, www.mydomain2.de); every domain should have it's own web app (as root).

       

      When I only define the virtual-server in standalone.xml nothing happens....

       

           <subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
                <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
                <virtual-server name="default-host" enable-welcome-root="true">
                     <alias name="localhost"/>
                     <alias name="example.com"/>
                </virtual-server>
                <virtual-server name="mydomain1" default-web-module="myapp">
                     <alias name="mydomain.de"/>
                     <alias name="www.mydomain1.de"/>
                </virtual-server>
           </subsystem>
      

       

      When I define additionally a virutal-host in jboss-web.xml inside my webproject (myapp\WEB-INF\jboss-web.xml) it works!

       

      <?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/j2ee/schema/jboss-web_5_1.xsd">
      
                <virtual-host>mydomain1</virtual-host>
      </jboss-web>
      

       

       

      When I have this jboss-web.xml inside my project I'm not able to start the web app under localhost (from eclipse).

       

      I don't want to modifiy the jboss-web.xml for every production deployment! (very ugly!)

       

      What's the normal way to develop a web app (local) and deploy them on JBossAS 7 reachable under a different domain?

       

        • 1. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
          am2605

          I would also like to know the answer to this.

           

          Also, are we limited to just one web app per host?  Is there an example of a setup such as this?

           

          server1/ <-- default web app is ROOT.war

           

          server2/foo <-- web app is foo.war

          server2/bar <-- web app is bar.war

           

          Can this be done?

           

          Many thanks,

          Andrew.

          • 2. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
            ctomc

            Hi guys,

             

            both options are possible

            you can add context root and don't use default-web-module="myapp"

             

            i would recommend you to add <context-root>/</context-root> in your jboss-web.xml and that will take care of your deployment on localhost in eclipse as this will bind it to / context (aka root context)

             

            as for many apps on one virtual host it is not a problem as long as context-root is diffrent.

            by default context-root is generated from war name.

             

            --

            tomaz

            • 3. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
              mr-678

              based on Tomaz answer (#2) I document the solutions that works for me:

               

              On server:

               

              standalone.xml

                      <subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
                          <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
                          <virtual-server name="default-host" enable-welcome-root="true">
                              <alias name="localhost"/>
                              <alias name="example.com"/>
                          </virtual-server>
                          <virtual-server name="mydomain1" >
                              <alias name="mydomain1.de"/>
                              <alias name="www.mydomain1.de"/>
                          </virtual-server>
                      </subsystem>
              

               

              jboss-web.xml inside project myapp:

              <?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/j2ee/schema/jboss-web_5_1.xsd">
                 <context-root>/</context-root>
                 <virtual-host>mydomain1</virtual-host>
              </jboss-web>
              

               

              On localhost (development with ide):

               

              standalone.xml:

                     <subsystem xmlns="urn:jboss:domain:web:1.0" default-virtual-server="default-host">
                          <connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="http"/>
                          <virtual-server name="default-host" enable-welcome-root="true">
                              <alias name="example.com"/>
                          </virtual-server>
                          <virtual-server name="mydomain1">
                              <alias name="localhost"/>
                          </virtual-server>
                      </subsystem>
              

               

              jboss-web.xml:

              no modifications

               

               

              If you have to configure more virtual servers:

              server-side:

              you can add easily more virtual-server

              local:

              you have to add also the virtual-server in standalone.xml.

              you can only use once the alias name "localhost" <alias name="localhost"/>

              I think for local development this is ok.

               

               

               

               

               

               

               

               

              • 4. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                mr-678

                Hi Tomaz,

                thanks alot for your helpful answer!

                 

                Your tip work's for me (see answer #3).

                 

                Summarized I think on Glassfish this works a litte bit 'smarter'... There you can assign a webapp to a webdomain only in the server configuration (without to add special deployment information inside the webproject).

                 

                Inside the web project (jboss-web.xml) knowledge about the name of the "virtual-host" is always necessary , or?

                • 5. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                  madhuy

                  Hi,

                   

                  I am using my local PC for launching the application.

                   

                  jboss-web.xml :

                   

                  <?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/j2ee/schema/jboss-web_5_1.xsd">

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

                            <virtual-host>sampletest</virtual-host>

                  </jboss-web>

                   

                  standalone.xml :

                   

                              <virtual-server name="sampletest" default-web-module="Sample">

                                  <alias name="localhost"/>

                              </virtual-server>

                   

                      <deployments>

                          <deployment name="Sample.war" runtime-name="Sample.war">

                              <content sha1="cf1619ae229f7fb9a8b9b45b42f10c1b5df7168f"/>

                          </deployment>

                      </deployments>

                   

                  But I am unable to lauch my application from browser

                  http://localhost:9990/sample

                  http://localhost:8080/sample

                   

                  My war file looks like

                   

                  Sample.war

                       -->WEB-INF

                                      ---> jboss-web.xml

                                      ---> web.xml

                                      ---> index.jsp

                       -->META-INF

                                      ---> MANIFEST.MF

                   

                  Can you let me know what could be the problem?

                   

                  Thanks and REgards,

                  Madhu

                  • 6. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                    mr-678

                    Hi Madhu Y,

                    inside jboss-web.xml you defined your context-root as '/'. So your application should be available as 'root' application directly under http://localhost:8080

                     

                    Regards, matthias

                    • 7. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                      madhuy

                      Hi Matthias,

                       

                      How should my link address should be.

                       

                      I tried with the following and unsuccessful.

                       

                      http://localhost:8080/Sample/index.jsp

                      http://localhost:8080/index.jsp

                       

                      Regards,

                      Madhu

                      • 8. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                        mr-678

                        Hi Madhu,

                        I just see that you placed your index.jsp in your WEB-INF folder. Try to move your index.jsp to root folder (Sample.war --> index.jsp). Content from the WEB-INF folder can only be accessed from the web-container ifself (if needed by a servlet).

                         

                        Regards, matthias

                        • 9. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                          madhuy

                          Hi,

                           

                          Sorry. Still I am not able to launch the application from browser

                           

                          REgards,

                          Madhu

                          • 10. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                            mr-678

                            Hi Madhu,

                            I've tried your config on a local project for me:

                             

                            When I use your config I get also no result from browser...

                             

                            Try to use following setup:

                            <virtual-server name="sampletest" >

                                      <alias name="localhost"/>

                            </virtual-server>

                             

                            Without default-web-module="Sample"

                             

                            This works in my test-seupt.

                             

                            Regards, matthias


                            • 11. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                              madhuy

                              Hi,

                               

                              Somehow it is not working in my case.

                               

                              When I deploy the war file standalone is getting updated as shown below

                               

                                          <virtual-server name="Sample" default-web-module="Sample.war">

                                              <alias name="localhost"/>

                                          </virtual-server>

                               

                              Can you tell me the link addresss you used?

                               

                              Regards,

                              Madhu

                              • 12. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                                mr-678

                                Hi Madhu,

                                when you modify standalone.xml it's important that your server is stopped! Else your modification is lost because during server shutdown the standalone.xml is updated by the server.

                                 

                                Stop your server -> modify your standalone.xml : remove default-web-module -> start your server.

                                 

                                With the configuration above you can reach your webapp as root-app (url: http://localhost:8080/index.jsp   http://localhost:8080 should also work - index.jsp is a default page)

                                 

                                Regards, matthias

                                • 13. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                                  madhuy

                                  Hi Matthias,

                                   

                                   

                                  Somehow it is still not working on our side.

                                  I am failing to understand how it is working for you.

                                  I stopped jboss server and updated xml file and now it looks like

                                   

                                              <virtual-server name="default-host" enable-welcome-root="false">

                                                  <alias name="localhost"/>

                                                  <alias name="example.com"/>

                                              </virtual-server>

                                              <virtual-server name="Sample">

                                                  <alias name="localhost"/>

                                              </virtual-server>

                                   

                                   

                                  I am attaching the sample.war and standalone.xml file which I am using.

                                   

                                  Can you let me know what is the error in my small application?

                                   

                                  Regards,

                                  Madhu

                                  • 14. Re: Interaction between virtual-server (in standalone.xml) and virtual-host (in jboss-web.xml)
                                    mr-678

                                    Hey Madhu,

                                    I've  loaded your project into my eclipse and was also surprised that it didn't work.

                                     

                                    I changed the virtual host to "sample-domain"

                                     

                                    jboss-web.xml:

                                     

                                    <?xml version="1.0" encoding="UTF-8"?>
                                    <jboss-web >
                                       <context-root>/</context-root>
                                       <virtual-host>sample-domain</virtual-host>    
                                    </jboss-web>
                                    

                                     

                                    standalone.xml:

                                     

                                    <virtual-server name="sample-domain">
                                           <alias name="localhost"/>
                                    </virtual-server>
                                    

                                     

                                    Now the App is avaiable under http://localhost:8080

                                     

                                    May be the virtual-host/virtual-server name have not to be identical to the war-file name...

                                     

                                    kind regards,

                                    matthias

                                     

                                    p.s. your index.jsp will not work correctly / hard coded post-path. May be it's useful you check out a jboss sample project

                                    1 2 Previous Next