Forum Discussion

Aklanion's avatar
Aklanion
Icon for Nimbostratus rankNimbostratus
May 26, 2020

Simple Reverse Proxy with iRules

Hello!

I simply want to create a reverse proxy for http://mediawiki.pva.sozvers.at/.

I created a Virtual Server http://f5wiki.pva.sozvers.at/ , enabled the http-profile, the stream Profile, configured a default-pool with the node http://mediawiki.pva.sozvers.at/ and finally wrote an iRule. I worked everything through at this site https://techdocs.f5.com/content/kb/en-us/products/big-ip_ltm/manuals/product/ltm-implementations-11-6-0/25.html But I want to do that with iRules instead of the Rewrite Profile+Policy, as I am new to f5 and would like to learn more about it. So here is my Try:

when HTTP_REQUEST {

 

STREAM::disable

 

if { [HTTP::host] eq "f5wiki.pva.sozvers.at"} {

 

HTTP::redirect "http://mediawiki.pva.sozvers.at"

 

     }

  }

  when HTTP_RESPONSE {

  STREAM::disable

 

  # Rewrite the Host header for redirects

 

  HTTP::header replace "http://mediawiki.pva.sozvers.at" "f5wiki.pva.sozvers.at"

 

  STREAM::enable

  }

 

 

 

It almost works. When calling the f5wiki.pva.sozvers.at-host i get redirected to my Node wiki.

Problem is:, the URL changes to mediawiki..., where I want the URL to stay the same.

 

Can someone help me? Thank you

  • Hi, I know u said u want to make this using iRule -  but I recommend you do it with policies. L7 policies use much less CPU than iRules and are easier to administer. 

     

    You create a virtual server and add a tcp and http profile - no other profiles needed. than you create a new pool with the node you need. than you create a new policy and in there, create a new rule with the conditions:

    When:

    "http host is any of f5wiki.pva.sozvers.at at request

     

    Then:

    Replace http host with value "mediawiki.pva.sozvers.at" at request

    Forward traffic to pool "your pool" at request

     

     

     

    Your failure with the iRule is the "http::redirect" . this sends a response to the client with the redirect to the new DNS name. this is wrong. If u want to do this with iRule:

     

    when HTTP_REQUEST {

    if { [HTTP::host] eq "f5wiki.pva.sozvers.at"} {

    HTTP::header replace "f5wiki.pva.sozvers.at" "mediawiki.pva.sozvers.at"

          pool /Common/yourpoolname

        }

     

     

    (not tested)

2 Replies

  • Hi, I know u said u want to make this using iRule -  but I recommend you do it with policies. L7 policies use much less CPU than iRules and are easier to administer. 

     

    You create a virtual server and add a tcp and http profile - no other profiles needed. than you create a new pool with the node you need. than you create a new policy and in there, create a new rule with the conditions:

    When:

    "http host is any of f5wiki.pva.sozvers.at at request

     

    Then:

    Replace http host with value "mediawiki.pva.sozvers.at" at request

    Forward traffic to pool "your pool" at request

     

     

     

    Your failure with the iRule is the "http::redirect" . this sends a response to the client with the redirect to the new DNS name. this is wrong. If u want to do this with iRule:

     

    when HTTP_REQUEST {

    if { [HTTP::host] eq "f5wiki.pva.sozvers.at"} {

    HTTP::header replace "f5wiki.pva.sozvers.at" "mediawiki.pva.sozvers.at"

          pool /Common/yourpoolname

        }

     

     

    (not tested)

    • Aklanion's avatar
      Aklanion
      Icon for Nimbostratus rankNimbostratus

      Thank you for your answer! I got it in the meantime ;)