Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

daveb2's avatar
Level 3

Cloudflare load balancer - endpoint health

I'm trying to setup load balancing to take advantage of DNS failover when one of our servers goes down.

I have two VMs configured as 'load balancers' with Laravel Forge. These connect internally to upstream servers (also VMs, in the same data centre).

I'm trying to setup a Load Balancer via Cloudflare. This is done at the DNS level. It requires the configuration of one or more 'pools' (which I take to mean geographic locations), with each pool containing one or more 'endpoints' (servers). I have a single pool containing two endpoints, corresponding to my two load balancer VMs.

Where I am getting stuck is in trying to configure monitoring for the endpoints within the pool - I assume that Cloudflare is unable to perform any kind of failover without being able to measure the health of each endpoint.

The sticking point it seems is that the load balancers only pass along requests to the upstream servers, and don't host anything themselves. Therefore, I don't have a way of determining whether they're up from a simply http/https request.

How have others solved this? Have you manually configured an nginx vhost on each load balancer, so that you can check the status of the load balancer?

0 likes
3 replies
LaryAI's avatar
Level 58

To set up endpoint health monitoring for your Cloudflare load balancer, you need a way to determine the health of your load balancer VMs. Since these VMs don't host content themselves but only pass requests to upstream servers, you can implement a simple health check endpoint on each load balancer. Here's how you can do it:

  1. Create a Health Check Endpoint: You can configure a simple HTTP endpoint on each load balancer that returns a 200 OK status if the load balancer is operational. This can be done by setting up a basic Nginx or Apache server with a static HTML page or a simple script.

  2. Configure Nginx (or Apache): If you're using Nginx, you can create a new server block to serve a health check page. Here's an example configuration for Nginx:

    server {
        listen 80;
        server_name your-load-balancer-ip;
    
        location /health {
            return 200 'OK';
            add_header Content-Type text/plain;
        }
    }
    

    This configuration listens on port 80 and responds with a 200 OK status for requests to /health.

  3. Set Up Cloudflare Health Checks: In the Cloudflare dashboard, configure a health check for each endpoint in your load balancer pool. Point the health check to the /health endpoint you created. Ensure that the health check is set to expect a 200 OK response.

  4. Test the Configuration: After setting up the health check, test it by accessing the /health endpoint directly in a browser or using a tool like curl to ensure it returns the expected response.

    curl http://your-load-balancer-ip/health
    

    You should see OK as the response.

  5. Monitor and Adjust: Monitor the health check results in the Cloudflare dashboard. If any issues arise, you can adjust the configuration or troubleshoot the load balancer as needed.

By implementing a simple health check endpoint, you enable Cloudflare to monitor the health of your load balancers and perform DNS failover when necessary. This approach ensures that your load balancers are always ready to route traffic to the upstream servers.

daveb2's avatar
Level 3

Hmm, so it seems the key is the option within the endpoint to configure a host header name. That appears to be for setting the SNI host name and I have had success like this.

Now I just need to solve the issue of the SSL certificate only being valid on one load balancer.

daveb2's avatar
Level 3

...managed to solve this too, load balancing now working. Hooray!

Please or to participate in this conversation.