Forum Discussion

network_76_2027's avatar
network_76_2027
Icon for Nimbostratus rankNimbostratus
May 29, 2015

F5 irule for reverse proxy with rewrite

I want to get data from website and display as a different url. The node and pool commands don't help because they seem to only work by IP, while I need to pass the hostname with subdomain to get the correct content.

 

If I get a request like,

 

https://app.localsite.com/templates/docs

 

I want to get data from this url,

 

http://docs.remotesite.com/index.html

 

but display the url

 

https://app.localsite.com/templates/docs/index.html

 

I looked at this post,

 

https://devcentral.f5.com/questions/irule-for-reverse-proxy-with-http-rewrite

 

which advises to use "node" or "pool" but those seem to use the IP instead of passing the entire hostname (with subdomain) to get that remote content. This is causing me to get the incorrect web content from the remote server.

 

Is there a way to do what I'm trying to accomplish?

 

16 Replies

  • Hi, you've tried to adapt the post in the way that you need and did not work? Could you post the iRule here?
  • My code looks like,

     

    when HTTP_REQUEST {
            switch -glob [HTTP::path] {
                    "/templates/docs" -
                    "/templates/docs/"
                    {
    
                     HTTP::header replace Host http://docs.remotesite.com
                     HTTP::uri "/resources/templates/index.html"
                     pool pool_docs
                    }
            }
    }

    pool_docs points to "docs.remotesite.com"

     

    My uri displayed in the browser stays at /templates/docs. I would like it to change to /templates/docs/index.html

     

    It does seem to be pulling content from docs.remotesite.com but there are some javascript files from that page that are not being downloaded "GET" correctly.

     

    They have a uri of /_static/jquery.js

     

    So how do I also change the browser url display and address the javascript files issue?

     

  • HTTP::header replace Host http://docs.remotesite.com

     

    i think this one should not have http://

     

    e.g.

     

    HTTP::header replace Host "docs.remotesite.com"

     

    My uri displayed in the browser stays at /templates/docs. I would like it to change to /templates/docs/index.html

     

    you need HTTP::redirect to change url in browser.

     

    HTTP::redirect

     

    https://devcentral.f5.com/wiki/iRules.HTTP__redirect.ashx

     

    It does seem to be pulling content from docs.remotesite.com but there are some javascript files from that page that are not being downloaded "GET" correctly.

     

    in your irule, it does change host header, uri and send traffic to pool_docs pool only when uri is /templates/docs or /templates/docs/. does the javascript also need to?

     

    • network_76_2027's avatar
      network_76_2027
      Icon for Nimbostratus rankNimbostratus
      So there is no way to grab content from another server and rewrite the clients URL without redirect? Similar to the Apache or 'nginx' commands, rewrite and proxy_pass ?
    • nitass_89166's avatar
      nitass_89166
      Icon for Noctilucent rankNoctilucent
      no, i think it is possible. what you need to do is to rewrite request and response properly. proxypass codeshare is one of examples. ProxyPass v10/v11 https://devcentral.f5.com/s/articles/proxypass-v10-v11
    • network_76_2027's avatar
      network_76_2027
      Icon for Nimbostratus rankNimbostratus
      I am running version BIG-IP 11.5.2 Build 0.0.141 Final When I copy and paste the ProxyPass code into my iRule and try to save I get an error, 01070151:3: Rule [/Common/rt18877] error: /Common/rt18877:1: error: [undefined procedure: @][@] If I remove the '@' from the beginning of the code, it will save the iRule, but I don't see any Proxy Pass activity while tailing logs.
  • HTTP::header replace Host http://docs.remotesite.com

     

    i think this one should not have http://

     

    e.g.

     

    HTTP::header replace Host "docs.remotesite.com"

     

    My uri displayed in the browser stays at /templates/docs. I would like it to change to /templates/docs/index.html

     

    you need HTTP::redirect to change url in browser.

     

    HTTP::redirect

     

    https://devcentral.f5.com/wiki/iRules.HTTP__redirect.ashx

     

    It does seem to be pulling content from docs.remotesite.com but there are some javascript files from that page that are not being downloaded "GET" correctly.

     

    in your irule, it does change host header, uri and send traffic to pool_docs pool only when uri is /templates/docs or /templates/docs/. does the javascript also need to?

     

    • network_76_2027's avatar
      network_76_2027
      Icon for Nimbostratus rankNimbostratus
      So there is no way to grab content from another server and rewrite the clients URL without redirect? Similar to the Apache or 'nginx' commands, rewrite and proxy_pass ?
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      no, i think it is possible. what you need to do is to rewrite request and response properly. proxypass codeshare is one of examples. ProxyPass v10/v11 https://devcentral.f5.com/s/articles/proxypass-v10-v11
    • network_76_2027's avatar
      network_76_2027
      Icon for Nimbostratus rankNimbostratus
      I am running version BIG-IP 11.5.2 Build 0.0.141 Final When I copy and paste the ProxyPass code into my iRule and try to save I get an error, 01070151:3: Rule [/Common/rt18877] error: /Common/rt18877:1: error: [undefined procedure: @][@] If I remove the '@' from the beginning of the code, it will save the iRule, but I don't see any Proxy Pass activity while tailing logs.