0

I am trying to serve the requests to my Site through Proxy machine using Load balancer. When i try to access the Site by hitting http://PROXYSERVER.com, the HomePage comes up fine retaining the address bar URL with http://PROXYSERVER.com.

Now, when i try to access internal links for example, http://PROXYSERVER.com/services/ then the address bar URLchanges to the APPSERVER URL http://APPSERVER01.com/services/


NOTE: The Page comes up fine but the address bar URL is getting changed.

Expected behaviour is when user requests http://PROXYSERVER.com/services/ then the address bar should retain the proxy URL while serving the request


Here is my code for load balancing,



        ProxyRequests off
 ServerName PROXYSERVER.com

                # WebHead1
                BalancerMember http://APPSERVER01:80/ route=node1
                                # WebHead2
               BalancerMember http://APPSERVER02:80/ route=node2
                Order Deny,Allow
                Deny from none
                Allow from all
                ProxySet lbmethod=byrequests
               #ProxySet lbmethod=bybusyness
                ProxySet stickysession=BALANCEID
        
        
                SetHandler balancer-manager
                Order deny,allow
                Allow from all
        
        # Point of Balance
        ProxyPass /balancer-manager !
        ProxyPass / balancer://mycluster/


Any suggestions will be appreciated.

5
  • 1
    That might be because you're missing the corresponding ProxyPassReverse directive (most likely), if that's the case I'll write up a pretty answer with that. Alternatively because your actual content contains absolute links that contain the app server hostname. That's more difficult, and requires a different strategy
    – HBruijn
    Jan 6, 2016 at 7:14
  • @HBruijn. Actual contents are build using PROXYSERVER Hostname. For instance, href for service is build as PROXYSERVER.com/services . But when i click on that href the address bar URL changes to APPSERVERxx.com/services. Point to be noted, even now the elements are build using the PROXYSERVER Hostname. Only issue i am facing is address bar URL changes to APPSERVER URL on accessing internal links except 'Home'.
    – Geo j
    Jan 6, 2016 at 7:32
  • That's because the missing ProxyPassReverse directive. When you go to a directory but omit the trailing / the app server sends an http redirect to the URL with trailing slash. The reverse proxy should rewrite that header to the URL base of the proxy server.
    – HBruijn
    Jan 6, 2016 at 7:38
  • @HBruijn . Do you mean the PROXYSERVER.com/services missing trailing slash. I am not used to editing options here. Its actually with trailing slash PROXYSERVER.com/services/. Did you meant adding code as ProxyPassReverse / balancer://mycluster/?
    – Geo j
    Jan 6, 2016 at 7:42
  • @HBruijn. With "ProxyPassReverse / balancer://mycluster/ " added to my conf file, its going into redirect loop. Hope that's what you meant. Thanks for the suggestions.
    – Geo j
    Jan 6, 2016 at 8:37

1 Answer 1

0

The configuration you posted and the symptoms you describe point to a missing ProxyPassReverse directive.

Without it any URL's in the Location, Content-Location and URI headers on HTTP redirect responses send by either one of you application servers won't be modified. That exposes the real name/URL of the application server and the visitor will be directed to that URL rather instead of that of the proxy-server.

You would see such headers for instance when you go to a directory http://example.com/dirname and omit the trailing slash /.
In that case the active application server will send a HTTP 301 "moved permanently" header and append the trailing slash.

A trace with curl -v proxyserver.com/services will show something along the lines of:

> GET /services HTTP/1.1
> Host: proxyserver.com
> User-Agent: curl/7.43.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< Date: Wed, 06 Jan 2016 09:27:31 GMT
< Server: Apache/2.2.15 (CentOS)
< Location: https://appserver01:/services/
< Content-Length: 328
< Connection: close
< Content-Type: text/html; charset=iso-8859-1
<

You resolve that by adding the correct ProxyPassReverse directive which tells Apache to rewrite such headers with that of the proxy URI

    # Point of Balance
    ProxyPass /balancer-manager !
    ProxyPass / balancer://mycluster/
    ProxyPassReverse / balancer://mycluster/

Depending on the version of Apache you're running you might experience behaviour similar to this older bug and could try explicit ProxyPassReverse directives for each member of the balancer pool:

    ProxyPass /balancer-manager !
    ProxyPass / balancer://mycluster/
    ProxyPassReverse / balancer://mycluster/
    # Ensure that headers sent by application servers get corrected:
    ProxyPassReverse / http://APPSERVER01:80/
    ProxyPassReverse / http://APPSERVER02:80/
3
  • Thanks for the in-depth explanation. I did try adding "ProxyPassReverse / balancer://mycluster/". But on accessing <PROXYSERVER.com/services/>; i am getting error as ERR_TOO_MANY_REDIRECTS.
    – Geo j
    Jan 6, 2016 at 10:56
  • Do you logs show anything, on both the proxy host and the application servers and does curl -v PROXYSERVER.com/services/ show where you get redirected to?
    – HBruijn
    Jan 6, 2016 at 11:02
  • I believe someconfiguration from the Application Server side is causing the issue. I will check and let you know. Thanks for the help
    – Geo j
    Jan 7, 2016 at 10:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .