Configuring WildFly as Reverse Proxy

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

In this tutorial we will learn how we can configure the Undertow subsystem to reverse proxy request from one application running on one host to another application running on an another host.  

 At first some some terminology: what is a reverse proxy ? the common usage of the term proxy usually refers to a forward proxy, which is a server that sits between your client and the destination machine. A forward proxy requires a configuration on the client machine in order to relay requests to the destination machine.

A reverse proxy, on the other hand does not require any special configuration on the client side. The client makes ordinary requests for content, the reverse proxy then decides where to send those requests, and returns the content as if it was itself the origin. The client is thus unaware that is request has been proxied.

A typical usage of a reverse proxy is to provide Internet users access to a server that is behind a firewall. Reverse proxies can also be used to balance load among several back-end servers, or to provide caching for a slower back-end server. In addition, reverse proxies can be used simply to bring several servers into the same URL space.

Undertow Web server can provide reverse proxy functionalities with just a few configuration tweaks. Let's create an example scenario, where we want to proxy requests on host 192.168.0.1 for an application named myapp-stable  to another version of the application named myapp-develop running on the host 192.168.0.2.

undertow reverse proxy

Creating a Reverse proxy is a two-step procedure: we will show how to do it via XML configuration (should not be your first option, however using the CLI for this purpose is a bit harder to complete because of the many escape sequences required). Open your server configuration on the machine 192.168.0.1 and include in the handlers section of your Undertow subsystem, the following configuration:


<subsystem xmlns="urn:jboss:domain:undertow:1.1">

   <handlers>
   . . . .
   <reverse-proxy name="myproxy">

    <host name="http://192.168.0.2/myapp-develop"/>

   </reverse-proxy>

   </handlers>

</subsystem>

Now all you have to do, is including in your Undertow's host section, a location element which references your reverse proxy: 


<host name="default-host" alias="localhost">
    . . .
   <location name="/myapp-stable" handler="myproxy"/>

 </host>

That's all! Now your requests from 192.168.0.1/myapp-stable will be transparentely redirected to 192.168.0.2/myapp-develop

Related articles available on mastertheboss.com

Wildfly 8 introduction

JBoss AS has a new name: as you probably know future versions of

Configuring Eclipse to use WildFly

This tutorial shows how to install JBoss Tools 4.3.1 plugin 

Maven configuration for Java EE 7 projects on WildFly

In this tutorial we will learn how to configure Maven Project Obj

Running WildFly with JDK 8

The JDK 1.8 early access is available for download at Oracle's si

Patching WildFly application server

The final version of WildFly 8.1.0 has been released and it conta

Configuring WildFly Batch Job Repository

WildFly ships with a subsystem named batch which is the administr