FortiADC
FortiADC enhances the scalability, performance, and security of your applications whether they are hosted on premises or in the cloud.
shafiq23
Staff & Editor
Staff & Editor
Article Id 422229
Description This article describes how to forward HTTP traffic by matching HTTP Host and URL using a LUA script.
Scope FortiADC.
Solution

Requirement:
A virtual server serves multiple websites with content routing enabled. The script must extract the HTTP Host or URL from the client request and route traffic to the proper server pool.

 

  • Create Scripting: Server Load Balance -> Scripting -> Create New.
  • Define name.
  • Input a Lua script statement.
  • Select Save.

 

when HTTP_REQUEST {
local host = (HTTP:header_get_value("Host") or ""):lower()
local uri = (HTTP:uri_get() or HTTP:path_get() or "/"):lower()

 

if host == "web1.dvwa.ftntlab" then
LB:routing("dvwa1")

 

elseif host == "web2.dvwa.ftntlab"
and (uri:find("/index.php", 1, true) or uri:find("/login.php", 1, true)) then
LB:routing("dvwa2")

 

elseif host == "web3.dvwa.ftntlab" then
LB:routing("dvwa3")

end
}

 

1.png

 

Assign a virtual server with the created script.
Server Load Balance -> Virtual Server -> Edit respective virtual server -> Enable Scripting -> Select created script.

 

2.png

 

Demonstration:

  • Simulate a request to FortiADC virtual server, e.g, https://web3.dvwa.ftntlab/login.php
  • Expect script to gather HTTP requests information; HTTP Host and URL, then forward traffic to the correct content routing and server pool.


FortiADC virtual server traffic log:

 

3.png

 

Debugging commands for troubleshooting:


diagnose debug module httproxy scripting set
diagnose debug module httproxy scripting_minor set
diagnose debug enable

 

Disable debugging output:


diagnose debug disable
diagnose debug module httproxy all unset

 

Related documentation about Scripting:
HTTP Scripting