cancel
Showing results for 
Search instead for 
Did you mean: 

load balance using http methods

Ahmed_Mohsen
Nimbostratus
Nimbostratus

We have 1 read/write node and two Read-only nodes, so we want all the Get http requests to be distributed equally in them and all other requests like POST, Patch, Delete to be forwarded to read/write node 

 

Example :-

Node1 : R/W " it will receives Get , Post,Patch,Delete "

Node2 : Read-only "it will receives Get Requests only "

Node3 : Read-only "it will receives Get Requests only "

 

Thank you in advance

9 REPLIES 9

MaximP
Cirrus
Cirrus

Hi, Ahmed.

You need to use an Irule, something like this

 

when HTTP_REQUEST {

 if { ([string toupper [HTTP::method]] equals "POST" ) or ([string toupper [HTTP::method]] equals "PATCH" ) or ([string toupper [HTTP::method]] equals "DELETE" ) } {

  node 1.1.1.1 443 

 } 

 elseif { [string toupper [HTTP::method]] equals "GET" } {

  pool POOL-name

 }

 else {

  HTTP::respond 405 content {

      <html>

      <head><title>HTTP Request denied</title></head>

      <body>Your HTTP requests are being throttled.</body>

      </html>

    }

 }

  

}

Ahmed_Mohsen
Nimbostratus
Nimbostratus

Thank you for your reply

Kindly when i deploy this iRule it shown me an error

0691T00000F60DMQAZ.png

MaximP
Cirrus
Cirrus

Yep, there were some extra brackets. I edited previos message, try again.

Thank you i will try it 🙂

Salam bro ,

 

I am trying to test the script in testing environment but it shown this error to me :-

 

0691T00000F6BfvQAF.png 

Thank you in advance

ka1021
Altostratus
Altostratus

Hello Ahmed,

i guess there are some extra spaces between "}" and "elseif".

 

when HTTP_REQUEST {

  if { ([string toupper [HTTP::method]] equals "POST" ) or ([string toupper [HTTP::method]] equals "PATCH" ) or ([string toupper [HTTP::method]] equals "DELETE" ) } {

    node XXXXXXX XX

    } elseif { [string toupper [HTTP::method]] equals "GET" } {

      pool XXXXXX

      } else {

      HTTP::respond 405 content {

 

   <html>

 

   <head><title>HTTP Request denied</title></head>

 

   <body>Your HTTP requests are being throttled.</body>

 

   </html>

 

   }

  }

}

ka1021
Altostratus
Altostratus

☝️ Try this

Thank you it's accepted now ,

before we start the testing in virtual server setting i will need to configure http profile or http-explicit ?

Should work with http profile.