views:

243

answers:

2

My application has two internal section:

  1. Upload section url: %URI%/upload/%action%
  2. Login section url: %URL%/Login/%action%

The code for Login section is located on one server 5.123.12.1, whereas the code for Upload is located on another server 5.123.12.2.

After the server routing, there will be further routing pertaining to the request parameters or action parameters.

How to construct rules for mod-rewrite and mod-cond in Apache configuration file for the two machines so that the routing can be done?

+1  A: 

For your setup I would use the following on another Apache server running as a front end.

<VirtualHost *:80>
  ServerName    your.domain.com
  RewriteEngine on
  ProxyPreserveHost on
  ProxyPassReverse /    http://5.123.12.1/
  ProxyPassReverse /    http://5.123.12.2/

  RewriteRule ^/Login(.*)   http://5.123.12.1/Login$1 [P,L]
  RewriteRule ^/upload(.*)  http://5.123.12.2/upload$1 [P,L]

</VirtualHost>

This is assuming that you have mod_rewrite enabled. I'm not sure you can use the ip address in the rewrite rules so you may have to set up an internal host name for the two servers you have listed.

neomorphic
A: 

You may be better off using a dedicated bit of load-balancing software such as HAProxy or Perlbal. The advantage being that you can balance your requests for the same URL across more than one backend server.

Failing that, there is a balancer module for Apache called mod_proxy_balancer:

<Proxy balancer://mycluster>
 BalancerMember http://192.168.1.50:80
 BalancerMember http://192.168.1.51:80
</Proxy>
ProxyPass /test balancer://mycluster/
danros