This article describes how to enable the HTTP cookie persistence in Virtual Server and verify the cookie insertion using the Wireshark packet capture.
FortiGate
The virtual server is configured for HTTP service and the real servers are reachable from the outside network.
https://community.fortinet.com/t5/FortiGate/Technical-Tip-Configure-virtual-server/ta-p/194457
From GUI:
Navigate to Policy & Objects -> Virtual Servers and enable HTTP cookie persistence.
From CLI:
config firewall vip
edit "Test-Website"
set uuid 94489f16-3561-51ee-c442-09f1dcbea373
set type server-load-balance
set extip 192.168.55.1
set extintf "any"
set server-type http
set ldb-method round-robin
set persistence http-cookie <-----
set extport 80
config realservers
edit 1
set ip 192.168.60.10
set port 80
next
edit 2
set ip 192.168.60.20
set port 80
next
end
HTTP cookie persistence works by using the injected cookies. The FortiGate distributes a new session to an actual server based on the selected Load Balance Method. If an HTTP cookie is present during the session, the FortiGate unit will direct all subsequent sessions with the identical HTTP cookie to the corresponding real server.
FortiGate will inject the cookie into the HTTP header of the server response packet.
The browser will also install the respective cookies after enabling cookie persistence. Check the browser cookies for confirmation:
Compare the forward traffic logs before and after enabling the HTTP cookie persistence to verify if the FortiGate is forwarding the traffic to the same real server.
Below are the Forward traffic logs before enabling HTTP cookie persistence: The traffic is load balanced to both servers in this case:
Below are the Forward traffic logs after enabling HTTP cookie persistence: FortiGate is forwarding the traffic to a single server for all sessions:
The following options are available for the 'config firewall vip' command when the type server is set to load-balance, server-type is set to HTTP or HTTPS and persistence is set to http-cookie:
http-cookie-domain-from-host
http-cookie-domain
http-cookie-path
http-cookie-age
From CLI :
config firewall vip
edit "Test-Website"
set uuid 94489f16-3561-51ee-c442-09f1dcbea373
set type server-load-balance
set extip 192.168.55.1
set extintf "any"
set server-type http
set ldb-method round-robin
set persistence http-cookie
set extport 80
config realservers
edit 1
set ip 192.168.60.10
set port 80
next
edit 2
set ip 192.168.60.20
set port 80
next
end
set http-cookie-domain-from-host enable <-----
next
end
set http-cookie-domain www.testwebsite.com
From CLI:
config firewall vip
edit "Test-Website"
set uuid 94489f16-3561-51ee-c442-09f1dcbea373
set type server-load-balance
set extip 192.168.55.1
set extintf "any"
set server-type http
set ldb-method round-robin
set persistence http-cookie
set extport 80
config realservers
edit 1
set ip 192.168.60.10
set port 80
next
edit 2
set ip 192.168.60.20
set port 80
next
end
set http-cookie-domain www.testwebsite.com <-----
next
end
From CLI:
config firewall vip
edit "Test-Website"
set uuid 94489f16-3561-51ee-c442-09f1dcbea373
set type server-load-balance
set extip 192.168.55.1
set extintf "any"
set server-type http
set ldb-method round-robin
set persistence http-cookie
set extport 80
config realservers
edit 1
set ip 192.168.60.10
set port 80
next
edit 2
set ip 192.168.60.20
set port 80
next
end
set http-cookie-domain "www.testwebsite.com"
set http-cookie-path "/contact.html" <-----
next
end
set http-cookie-age 10
Confirm the cookie age from the browser cookie output:
The Fortinet Security Fabric brings together the concepts of convergence and consolidation to provide comprehensive cybersecurity protection for all users, devices, and applications and across all network edges.
Copyright 2025 Fortinet, Inc. All Rights Reserved.