Test HAProxy

To check whether HAproxy is working properly, we can do the following.
First, prepare test.php file with the following content:

< ?php
header('Content-Type: text/plain');
echo "Server IP: ".$_SERVER['SERVER_ADDR'];
echo "\nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];

This PHP file will tell us which server (i.e., load balancer) forwarded the request, and what backend web server actually handled the request.
Place this PHP file in the root directory of both backend web servers. Now use curl command to fetch this PHP file from the load balancer (
When we run this command multiple times, we should see the following two outputs alternate (due to the round robin algorithm).
Server IP:

Server IP:

If we stop one of the two backend web servers, the curl command should still work, directing requests to the other available web server.