How can i have Apache forward requests to different app servers based on URL pattern?

Assuming you already know how to set up Apache and Tomcat to talk to each other using workers2.properties file.

The Apache workers2.properties file for such a configuration should look like (More explanation at the end):\

—-workers2.properties file—

[shm]
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
file=anon

# Defines a load balancer named lb. Use even if you only have one machine.
[lb:lb]
worker=ajp13:166.208.0.11:8080
timeout=30
attempts=2
recovery=90
StickySession=1
noWorkersMsg=Server Busy please retry after some time.
noWorkerCodeMsg=503

# Defines a load balancer named lb. Use even if you only have one machine.
[lb:lbX]
worker=ajp13:166.208.0.11:9090
timeout=30
attempts=2
recovery=90
StickySession=0
noWorkersMsg=Server Busy please retry after some time.
noWorkerCodeMsg=503

# Example socket channel, override port and host.
[channel.socket:166.208.0.11:8080]
port=8080
host=166.208.0.11
tomcatId=server1
group=lb
lbfactor=100

# Example socket channel, override port and host.
[channel.socket:166.208.0.11:9090]
port=9090
host=166.208.0.11
tomcatId=serverX
group=lbX
lbfactor=100

[ajp13:166.208.0.11:8080]
channel=channel.socket:server1

[ajp13:166.208.0.11:9090]
channel=channel.socket:serverX

[uri:/myapp/craft/*]
group=lbX

[uri:/myapp/*]
group=lb

[status:]
info=Status worker, displays runtime information

[uri:/jk-stinc/*]
info=The Tomcat /jkstatus handler
group=status:

 

———————–

Notice that two load-balance groups lb1 and lbX have been defined. All URLs of the form /myapp/craft are handled by load balance group lbX. All URLs of the form /muapp are handled by load balance group lb. One tomcat server is running166.208.0.11:8080, and another on 166.208.0.11:9090. The latter one will handle all URLs of the form /myapp/craft. While the former one will handle all URLs of the form: /myapp.

Tested in: Apache 2.2.8/Linux

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: