Forum Discussion

Satriaji's avatar
Satriaji
Icon for Cirrus rankCirrus
Mar 04, 2022

Converting NGINX script to F5 iRules

  • Hii Everyone,
  • Can i ask about converting NGINX script to iRules F5?

I have a NGINX script :

[root@webdplk conf.d]# cat simponi.conf
server {
listen 80;
listen 443;

server_name dplk.bni.co.id;

location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_pass http://192.168.3.187;
}

location /mobile {
rewrite /mobile(.*) /$1 break;
proxy_pass http://192.168.3.186:7005/;
}
}

server {
listen 7005;

server_name dplk.bni.co.id;

location / {
rewrite /mobile(.*) /$1 break;
proxy_pass http://192.168.3.186:7005/;
}
}
[root@webdplk conf.d]#


How if that script if convert to F5 IRules??

 

Thankyouu

  • Something like this? (Assumes you don't need a virtual server listening on port 7005, but that the pool member you're forwarding traffic to is listening on that port and the virtual that is listening on 443 will translate)

    when HTTP_REQUEST {
      if { [HTTP::host] eq "dplk.bni.co.id" } {
        switch -glob [HTTP::uri] {
          "/" {
            pool pool_192.168.3.187_80
            HTTP::header insert X-Forwarded-Host [HTTP::host]
            HTTP::header insert X-Forwarded-Server [HTTP::host]
            HTTP::header insert X-Forwarded-Proto "https"
            HTTP::header insert X-Forwarded-For [IP::client_addr]
          }
          "/mobile*" {
            pool pool_192.168.3.186_7005
            set uri [string map {"/mobile" ""} [HTTP::uri]]
          }
          default {
            reject
          }
        }
      }
    }