WildFly (Jboss 10) HTTP/AJP/HTTPS Reverse Proxy

Posted by

Undertow subsystem can be used to reverse proxy requests to an application on a remote machine or it can be used to proxy it to same machine

For example you want to proxy all requests for host 127.0.0.1 with context “/host1” to another remote application running on 127.0.0.2 with updated context as “/host2”

Reverse Proxy to remote Host:

Host1 (127.0.0.1) (/host1) —————> PROXY ——————> Host2 (127.0.0.2) (/host2)

As shown above any client request coming to 127.0.0.1 with context /host1 will be proxied to 127.0.0.2 with context /host2 .

Reverse Proxy to same Host:

Host1 (127.0.0.1) (/host1) —————> PROXY ——————> Host1 (127.0.0.1) (/host3)

As shown above any client request coming to 127.0.0.1 with context /host1 will be proxied to same host 127.0.0.1 with updated context /host3 .

** Please note reverse proxy may impact the POST/PUT Requests.

1. Define location you want to be proxied 

<host name="default-host" alias="localhost">
     <location name="/host1" handler=“myProxy”/>
</host>

2. Define handler for the above location (destination context where you want to proxy) 

<handlers>
	<reverse-proxy name="myProxy">
		<host name="myHost" outbound-socket-binding="ajp-remote" scheme="ajp"
			path="/host2" instance-id=“myInstance " />   
	</reverse-proxy>
</handlers>

3. Map the outbound-socket-binding to corresponding AJP/HTTP/HTTPS

<outbound-socket-binding name="ajp-remote">
	<remote-destination host=“127.0.0.2 " port="8080" />
</outbound-socket-binding>

Port should be same as the one jboss is running and which http scheme you are using, above code is shown for ajp.

Leave a Reply

Your email address will not be published.