LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   apache : Obtain part of url in proxy balancer from one balancer member (https://www.linuxquestions.org/questions/linux-software-2/apache-obtain-part-of-url-in-proxy-balancer-from-one-balancer-member-4175482784/)

floss 10-30-2013 10:40 AM

apache : Obtain part of url in proxy balancer from one balancer member
 
I have cluster setup of Apache server . Behind this I have 2 Jboss instances which is load balanced by apache.

The configuration look somewhat like the below

<VirtualHost *:1111>
ServerAdmin admin@example.com
ServerName www.example.com

DocumentRoot "/apps"
ErrorLog "logs/https.www.example.com.-error_log"
TransferLog "logs/https.www.example.com-access_log"
LogLevel warn


<Directory "/apps">
Options -Indexes +FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>


SSLProxyEngine On
SSLProxyVerify On


SSLProxyMachineCertificateFile "/apps/apache/conf/ssl/int/proxy.pem"
SSLProxyCACertificateFile "/apps/apache/conf/ssl/int/cert.pem"


RewriteEngine On

Header set Cache-Control "max-age=60, public"

<Proxy balancer://2node-aa>

BalancerMember https://app01:8089 route=node1
BalancerMember https://app02:8089 route=node2

ProxyPreserveHost On

ProxyPass /aa balancer://2node/aa stickysession=JSESSIONID|jsessionid
ProxyPass /static balancer://2node/static stickysession=JSESSIONID|jsessionid

ProxyPassReverse /aa balancer://2node/aa
ProxyPassReverse /static balancer://2node/static



ProxyPass /1/aa https://app01:8089/aa
ProxyPass /2/aa https://app02:8089/aa

ProxyPassReverse /1/aa https://app01:8089/aa
ProxyPassReverse /2/aa https://app02:8089/aa

ProxyPass /bb balancer://2node/rest stickysession=JSESSIONID|jsessionid
ProxyPassReverse /bb balancer://2node/bb

</VirtualHost>


In the url access certain part of the url i want it to be routed from second node i.e node2 of jboss.

e.g. if i am accessing http://www.example.com/aa/login/login.jsp i need this request to be process by node2 app02 only.

Rest of the request should load balance as normal access. How do i set the apache to do it ?

I have tried lot of rewrite,<Location> and ProxyPassMatch none has worked so far.

Please Help. Thanks in advance.

sag47 10-30-2013 10:56 AM

You need to separate the nodes into different balancers. e.g. here's my apache config for balancing reads and writes across servers.

Code:

  # Load balancing to different nodes based on type of requests
  # Send POST, PUT, and DELETEs to writeBalancer
  RewriteCond %{REQUEST_METHOD} ^(POST|PUT|DELETE)$
  RewriteRule ^/(.*)$ balancer://writeBalancer$1 [P]
  # Send GET, HEAD, and OPTIONS to readBalancer
  RewriteCond %{REQUEST_METHOD} ^(GET|HEAD|OPTIONS)$
  RewriteRule ^/(.*)$ balancer://readBalancer$1 [P]

You can add the same BalancerMember to multiple balancers. See the rewrite flags for a description of [P].

SAM

floss 10-30-2013 05:12 PM

Hi SAM,

Thanks for your reply.

I did try this but it does not work.


<Proxy balancer://2node-aa>

BalancerMember https://app02:8080 route=node2

</Proxy>
RewriteRule ^/aa/login/(.*)$ balancer://2node-aa$1 [P]

I had put it just above the balancer with two node.
Don't see any error in the log file.

floss 12-01-2013 10:21 AM

I used the below statement in the configuration file which resolved the issue.

<Proxy balancer://2node-aa>

BalancerMember https://app02:8080 route=node2

</Proxy>

RewriteRule ^/aa/login/(.*)$ balancer://2node-aa%{REQUEST_URI} [P,QSA,L]

This link help me.

http://stackoverflow.com/questions/1...url-redirectio

-Thanks

sag47 12-01-2013 03:30 PM

Quote:

Originally Posted by floss (Post 5055491)
Hi SAM,

Thanks for your reply.

I did try this but it does not work.


<Proxy balancer://2node-aa>

BalancerMember https://app02:8080 route=node2

</Proxy>
RewriteRule ^/aa/login/(.*)$ balancer://2node-aa$1 [P]

I had put it just above the balancer with two node.
Don't see any error in the log file.

If you read how mod_rewrite works you'd see that you're not grouping the regex properly if you need the full request string... You'd need something like this....

Code:

<Proxy balancer://2node-aa>
  BalancerMember https://app02:8080 route=node2
</Proxy>
RewriteRule ^(/aa/login/.*)$ balancer://2node-aa$1 [P]

Notice now I grouped the RewriteRule. Before you had...
Code:

RewriteRule ^/aa/login/(.*)$ balancer://2node-aa$1 [P]
which means if someone visited http://example.com/aa/login/some/url then what would be passed to the proxy server is "some/url". Where the following actually passes "/aa/login/some/url" like you would expect.
Code:

RewriteRule ^(/aa/login/.*)$ balancer://2node-aa$1 [P]
You should really read the documentation to understand the solution provided to you and then adjust the solution to what you actually want. In your case the %{REQUEST_URI} will cover the whole URI so the parenthesis are no longer needed in the RewriteRule string. See apache documentation on mod_rewrite.

SAM


All times are GMT -5. The time now is 01:41 AM.