Forum Discussion

Ahmed_Mohsen's avatar
Ahmed_Mohsen
Icon for Nimbostratus rankNimbostratus
Oct 13, 2021

load balance using http methods

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

  • 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>

        }

     }

      

    }

  • Thank you for your reply

    Kindly when i deploy this iRule it shown me an error

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

    • Ahmed_Mohsen's avatar
      Ahmed_Mohsen
      Icon for Nimbostratus rankNimbostratus

      Salam bro ,

       

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

       

       

      Thank you in advance

  • 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>

     

       }

      }

    }

    • Ahmed_Mohsen's avatar
      Ahmed_Mohsen
      Icon for Nimbostratus rankNimbostratus

      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 ?