Hi,

I'm implementing two reverse proxies reverse proxy in front of two application 
server farms in different data centers, where each customer has one specific 
target server. The rewrite rules below are working, but might do several 
external
redirects, which I'd like to reduce if possible. 

It basically works like that:
 * the first path component in the request uri is the customer name
 * look up this customer name in a RewriteMap
   * if found, proxy to the target server
   * otherwise look if it is found in the map of the other data center and 
     redirect there

Both proxies are reached with the same DNS name, but have their own canonical 
name. 
There are web service clients that don't support redirects for individual 
calls. 
Therefore these are redirected once to the canonical hostname when they request 
their 
customer name directly. Some accounts may be used with HTTPS only.

Below are the rules. Do you see a way to simplify them without changing the 
logic, to
avoid repeated redirects to the same server?

Thanks
Rainer


           # canonical name 
        ServerName login1.portal.example.com
            # public common name
        ServerAlias login.portal.example.com
        UseCanonicalName On

        # map of customer instances that are proxied here
        RewriteMap  c2back dbm:/etc/apache2/portal/customer2backend.db
        # map of customer instances in the other datacenter
        RewriteMap  c2other dbm:/etc/apache2/portal/customer2other.db
        # map of local HTTPS-only accounts
        RewriteMap c2https dbm:/etc/apache2/portal/customer2https.db
        
        # if account is set to HTTPS only, redirect to same HTTPS URL
        RewriteCond %{HTTPS} =off
        RewriteCond ${c2https:$1} =s
        RewriteRule ^/([^/]+)(/.*)? https://%{SERVER_NAME}$1$2 [R,L]
           
        # redirect requests for a customer name to canonical name
        RewriteCond %{HTTP_HOST} !=login1.portal.example.com
        RewriteRule ^/([^/]+)/?$ /$1/ [R,L]

        # the main proxy rule: lookup backend server for customer, setup ENV
        # and send proxy request
        # map  contains customername=>backendhost/applicationname
        RewriteCond ${c2back:$1} ^(.+)$
        RewriteRule ^/([^/]+) - [E=CUST:$1,E=TARGET:%1,C]
        RewriteRule ^/([^/]+)(/.*)? http://%{ENV:TARGET}$2 [P,L]

        ProxyPassInterpolateEnv on
        ProxyPassReverse /${CUST}/ http://${TARGET}/ interpolate

        # redirect others to the other proxy if found in map
        # map contains  customername=>otherproxyhostname
        RewriteCond %{HTTPS} =on
        RewriteRule .* - [E=SSL:s]
        RewriteCond ${c2other:$1} ^(.+)$
        RewriteRule ^/([^/]+)(/.*)? http%{ENV:SSL}://%1/$1$2 [R,L]

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscr...@httpd.apache.org
   "   from the digest: users-digest-unsubscr...@httpd.apache.org
For additional commands, e-mail: users-h...@httpd.apache.org

Reply via email to