Tel Map

Blog

WildFly 10 with Apache and AJP

This article demonstrates how inbound request from a webserver (Apache) can be proxied to an application server (WildFly 10) using the Apache JServ Protocol (AJP). For more information on what AJP actually is, take a look at https://en.wikipedia.org/wiki/Apache_JServ_Protocol .

WildFly 10 Configuration

First you have to add an ajp-listener to the undertow subsystem (line 4).

standalone.xml –  undertow subsystem:

Then you also have to add a socket-binding (line 4).

standalone.xml – socket binding:

Apache Configuration

On my linux I am using the Apache module jk for connecting WildFly 10 with Apache. First you have to check if that module is already installed on your machine.

If you see a line like the one below the module is already installed.

Please make sure you run this command as the root user of the operating system.

If the module is not listed, you have to install it. This greatly depends on your linux distribution. On debian it looks like this:

Afterwards you also have to enable the module using

Installing this module also generates a default jk-workers.properties.default file. For my linux distribution this file can be found under /etc/apache2. You have to copy that file to  jk-workers.properties and put in the settings for the specific Apache JServ Protocol connections. E.g.

VirtualHost Configuration

To use the configured Apache JServ Protocol for example for a subdomain, you have to add a new VirtualHost configuration to your Apache server. In my example for SSL this looks like this:

You notice that this configuration uses SSL by taking a look at the first line of the file

which is the port for SSL. Otherwise port 80 has to be used instead. The line

actually takes care of routing all requests to WildFly. JkUnMount removes certain URLs from being routed through Apache JServ Protocol. If WildFly delivers a 503 error, this way a maintenance page is displayed, instead.

Port Offset

If you are running multiple applications servers on the same machine, you do not want to adjust all ports in each standalone.xml separately. Typically you simple set a port offset for the particular application server. This value is added to each port specified in the socket-binding-group section (see above).

The default port offset is 0 as you can see in the first line of the socket-binding-group section.

It can be overridden by a command line argument for the application server, however.

Typically the right way to do this is to put the port offset parameter into the file standalone.conf in the bin directory of WildFly. You simply have to add a line like this:

standalone.conf:

standalone.xml:

So in my example instead of AJP listening on port 8009 like configured in the standalone.xml, it will listen on port 28009. That is also why I configured that port in jk_workers.properties.

Port Offset Bug in WildFly 10

One thing that totally got me confused, however, is the following. After setting this up completely and starting WildFly, I took a look a the console log to see if the listener is actually properly starting up.

In the console log I saw the following lines:

So for the http listener the port offset is correctly added to the port specified in the standalone.xml. For the AJP listener, however, the port offset was not added.

After 2 hour of trying to figure out why WildFly is not listening on the correct port, I actually took a look at netstat.

Only then I figured out that actually WildFly was listening on the correct port. Only the console log output seems to be wrong. So if I hadn’t looked at the console log in the first place, everything would have worked just fine…

Summary

This article demonstrates how to set up WildFly 10 and Apache using the Apache JServ Protocol. Since I could only find outdated articles about this on the internet, I hope this will save you some time setting this up. If you have any questions or comments. Please leave a comment below.

5 Antworten auf „WildFly 10 with Apache and AJP“

  1. Igor Vuković

    „Service Temporarily Unavailable The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

    1. Igor Vuković

      The reason is
      connect to 127.0.0.1:18009 failed …. si i think the problem is in the AJP of Wildfly

      my port offset is 1000 in standalone.xml

  2. Cyp

    Please I need a complete guide on how to link apache 2.4 to wildfly in windows 10. I am running windows 10, have wildfly and Apache running independently. Please I want to know how to link them.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert