Search code examples
javawildfly-8

Not able to deploy multiple war packages to different hosts listening to different ports on Wildfly 8.1.0 Final?


My use case involves deployment of two different packages (war files) on a single Wildfly server.

In standalone-full.xml my socket-binding-group looks like this after addition of the extra socket as below

<socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">
    <socket-binding name="management-http" interface="management" port="${jboss.management.http.port:9990}"/>
    <socket-binding name="management-https" interface="management" port="${jboss.management.https.port:9993}"/>
    <socket-binding name="ajp" port="${jboss.ajp.port:8009}"/>
    <socket-binding name="http" port="${jboss.http.port:8080}"/>
    <socket-binding name="https" port="${jboss.https.port:8443}"/>
    <socket-binding name="jacorb" interface="unsecure" port="3528"/>
    <socket-binding name="jacorb-ssl" interface="unsecure" port="3529"/>
    <socket-binding name="messaging-group" port="0" multicast-address="${jboss.messaging.group.address:231.7.7.7}" multicast-port="${jboss.messaging.group.port:9876}"/>
    <socket-binding name="txn-recovery-environment" port="4712"/>
    <socket-binding name="txn-status-manager" port="4713"/>
    <socket-binding name="mylocal-internal" port="8099"/>
    <outbound-socket-binding name="mail-smtp">
        <remote-destination host="localhost" port="25"/>
    </outbound-socket-binding>
</socket-binding-group>

In standalone-full.xml my Subsystem looks like this after addition of the external server as shown below

<subsystem xmlns="urn:jboss:domain:undertow:1.1">
            <buffer-cache name="default"/>
            <server name="default-server">
                <http-listener name="default" socket-binding="http"/>
                <host name="default-host" alias="localhost">
                    <location name="/" handler="welcome-content"/>
                    <filter-ref name="server-header"/>
                    <filter-ref name="x-powered-by-header"/>
                    <single-sign-on path="/"/>
                </host>
            </server>
            <server name="mylocal-internal-server">
                <http-listener name="config-listener" socket-binding="mylocal-internal"/>
                <host name="mylocal-host" alias="localhost2">
                    <location name="/" handler="welcome-content"/>
                    <filter-ref name="server-header"/>
                    <filter-ref name="x-powered-by-header"/>
                    <single-sign-on path="/"/>
                </host>
            </server>
            <servlet-container name="default">
                <jsp-config/>
            </servlet-container>
            <handlers>
                <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
            </handlers>
            <filters>
                <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>
                <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
            </filters>
   </subsystem>

Also my jboss-web.xml file for myapp war looks like the following

<?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_8_0.xsd">
  <context-root>/myapp</context-root>
  <virtual-host>mylocal-host</virtual-host>
  <server-instance>mylocal-internal-server</server-instance>
</jboss-web>

Everything deploys successfully when i upload and deploy the war file through admin console at 9990, but when i try accessing myapp on the new port 8099 then i am getting 404 Not Found error. I am trying to access it like http://mydomain:8099/myapp

However if i deploy my war for port 8080 then it is available successfully at http://mydomain:8080/myapp

Please advice on this.


Solution

  • A bit of history for this answer taken from the comments to complete the picture.

    • The configuration setup for this question is taken from this existing off-site question and answer in the JBoss forums, which is a clear indication there is little wrong with the setup as it is; the proper configuration is in place, there is simply something that still needs to be re-configured in it. https://developer.jboss.org/message/857103

    • With a little comparison, the only difference that could be spotted was that the host alias configuration was different (localhost -> localhost2). However the source material in the above JBoss forum thread is not configured for production deployment, it is a setup for development on the localhost. This question IS about deploying the server in production behind a proper domain name. So that's where the missing link is to be found.

    • As this existing related stackoverflow question indicates, you need to put the proper host name in the alias to make it work. Wildfly / Undertow : Multiple aliases for one host

    And that was ultimately the solution to this problem too; add the domain name to the host alias.

    <host name="mylocal-host" alias="localhost2, my.domainname.com">
      ...
    </host>