application server

2 min read

DevOps engineers and IT operators always need to setup load-balancing on WildFly for web applications in their systems.

Benefits of using the Apache web server with WildFly


  • Speed: Apache web server is faster at serving static context.
  • Security: Apache web server can become a smart proxy server. WildFly can be configured to accept connections from a single IP (the server hosting Apache).
  • Load balancing and clustering: Using Apache as front-end, DevOps engineer can distribute traffic to multiple WildFly server instances. For example, if one of the servers fails, the communication transparently continues to another node in the cluster.

Using the mod_jk library

The mod_jk library is a common solution to front WildFly with the Apache web server.


Installing Apache

sudo apt-get update
sudo apt-get install -y apache2

Installing mod_jk

sudo apt-get install libapache2-mod-jk

Confirm that the module has been enabled

sudo apache2ctl -M

Modify the virtual host within for the default configuration file: default

Directory: /etc/apache2/sites-enabled

<VirtualHost *:80>
    ServerAdmin webmaster@localhost

    JkMount /* loadbalancer
    <Directory />
        Options FollowSymLinks
        AllowOverride None

     ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Forward all URLs, unmount one or two URLs so that static data can be served from Apache web server.

<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        JkMount /* loadbalancer
        JkUmount /images/* loadbalancer

        <Directory />
                Options FollowSymLinks
                AllowOverride None

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

Directory: /etc/libapache2-mod-jk

# Define worker list
# Set properties for worker1 (ajp13)

# Set properties for worker2 (ajp13)

Restart Apache web server

sudo /etc/init.d/apache2 restart

Default configuration in the ha profiles: defines the AJP connector


<subsystem xmlns="urn:jboss:domain:undertow:1.1">
    <buffer-cache name="default"/>
    <server name="default-server">
        <ajp-listener name="ajp" socket-binding="ajp"/>
        <http-listener name="default" socket-binding="http"/>


<socket-binding-group name="standard-sockets" default-interface="public" port-offset="0">
    <socket-binding name="management-http" interface="management" port="9990"/>
    <socket-binding name="management-https" interface="management" port="9993"/>
    <socket-binding name="ajp" port="8009"/>

Configuring mod_proxy

Install and enable mod_proxy

sudo apt-get install libapache2-mod-proxy-html
sudo a2enmod proxy-http

Forward an application with context path of /app*

ProxyPass         /app  http://localhost:8080/app
ProxyPassReverse  /app  http://localhost:8080/app
Orestis Pantazos

Orestis Pantazos

DevOps Engineer