Configure HTTP load balancing for servers behind a FortiGate firewall
This guide provides an example of how to configure HTTP traffic load balancing between servers behind a firewall.
These instructions are relevant for FortiOS versions 6.x and 7.x. If you have a different version of FortiOS, you can find instructions in the official FortiGate documentation.
- If you have not yet connected the FortiGate to the servers, connect the FortiGate firewall to the servers in the Selectel infrastructure.
- Create a health check.
- Create a virtual server.
- Create a security policy.
- Verify load balancing operation.
1. Connect the FortiGate firewall to the servers in the Selectel infrastructure
Follow the instructions in Connecting products and services via a global router.
2. Create a health check
Health Check determines the operability of a server behind the firewall based on configured parameters. If a server behind the firewall stops responding, FortiGate will redirect requests to available servers.
Graphical interface
CLI
- Connect to the firewall.
- Make sure that in the System → Feature Visibility section, the Load Balance toggle is enabled. If the toggle is disabled, the sections for load balancing settings will not be displayed.
- Go to Policy & Objects → Health Check.
- Click Create New.
- In the Name field, enter the name of the health check.
- In the Type field, select the HTTP health check protocol.
- In the Interval field, enter the frequency of server health checks in seconds or leave the default value.
- In the Timeout field, enter the maximum time to wait for a response from the server behind the firewall in seconds or leave the default value.
- In the Retry field, enter the number of failed health checks after which the server behind the firewall will be excluded from load balancing or leave the default value.
- In the Port field, enter the port for checking the server behind the firewall. The default port is 80.
- In the URL field, enter the path to the file on the server behind the firewall where FortiGate will send the GET request to verify the server status. For example,
/health.html. - In the Matched content field, enter the text that FortiGate will look for in the GET request response body. For example,
OK. - Click OK.
3. Create a virtual server
A Virtual Server accepts incoming traffic and redirects it to real servers (Real Server) — the IP address and port of the server behind the firewall. You can add multiple real servers so that FortiGate automatically distributes the load between them.
Graphical interface
CLI
-
Go to Policy & Objects → Virtual Servers.
-
Click Create New.
-
In the Name field, enter the name of the virtual server.
-
In the Type field, select HTTP.
-
In the Interface field, select the firewall interface through which requests to the virtual server will arrive:
- to have requests arrive via a single interface, select that interface. For example, wan1;
- to have requests arrive via all interfaces, select any.
-
In the Virtual Server IP field, enter the public IP address of the firewall that you received in the ticket after ordering the firewall.
-
In the Virtual Server Port field, enter the firewall port to which incoming requests will be directed.
-
In the Load Balancing Method field, select a load balancing method.
-
Optional: to have all requests from a single user within a session handled by the same server behind the firewall, in the Persistence field, select HTTP Cookie. Learn more about session persistence in the Session Persistence subsection of the Load balancing protocols and methods guide.
-
In the Health Check field, select the health check you created in Step 2.
-
Optional: to use a single TCP connection with a server behind the firewall when processing multiple HTTP requests, enable the HTTP Multiplexing toggle.
-
Optional: to preserve the user's IP address in the
X-Forwarded-ForHTTP header, enable the Preserve Client IP toggle. -
In the Real Servers block, click Create New.
-
In the IP Address field, enter the private IP address of the server behind the firewall.
-
In the Port field, enter the port of the server behind the firewall to which requests will be redirected. The default port is 80.
-
Click OK.
-
Repeat steps 14–17 for every server behind the firewall that you want to add to load balancing.
-
Click OK.
4. Create a security policy
A security policy determines what traffic the firewall will allow between its interfaces. For example, you can use a policy to allow HTTP traffic to a virtual server. If no security policies are created, all traffic is dropped.
Graphical interface
CLI
FortiOS 6.x
FortiOS 7.x
- Connect to the firewall.
- Go to Policy & Objects → IPv4 Policy.
- Click Create New.
- In the Name field, enter the name of the security policy.
- In the Incoming Interface field, select the firewall's public interface.
- In the Outgoing Interface field, select the firewall's private interface.
- In the Source field, select all.
- In the Destination field, select the virtual server that you created in Step 3.
- In the Schedule field, select always.
- In the Service field, select HTTP.
- In the Action field, select Accept.
- In the Inspection Mode field, select Proxy-based.
- Disable the NAT toggle. Servers behind the firewall will receive the original connection IP addresses.
- Click OK.
5. Verify load balancing operation
Graphical interface
CLI
FortiOS 6.x
FortiOS 7.x
-
Go to Monitor → Load Balance Monitor.
-
In the Real Server column, next to the real server IP address, click .
-
In the Status column, check the status of the servers:
Up— the server is active, FortiGate is sending requests to it;Down— the server is not responding, FortiGate is not sending requests to it.