I recently faced an issue where my Cloudflare managed API endpoint was functioning correctly—returning a 200 OK status when I hit the endpoint manually—but Cloudflare’s Load Balancer was reporting a “Critical” health status. After a lot of trial and error with some investigation, I found that the problem was with the Header Settings in the monitor health check. This post will outline the steps I took to get the health monitor check to return healthy.
Initial Troubleshooting
I created a simple endpoint in my API specifically for the health monitor. The endpoint was a simple GET and returned a 200 along with the server name as the body text. This endpoint was returning a 200 response code from Postman and through my browser, so I double checked that the monitor configuration was correct in Cloudflare:
- URL: I made sure it was pointing to the correct endpoint that was returning 200 when I manually hit the url.
- Method: Set to
GET
as my API was expecting. - Timeout and Frequency: Set to 60.
These checked out but the health of the monitor was still returning “Critical”. At first I didn’t think that I needed to set any additional headers, ignorantly thinking that Cloudflare would would set default headers of the monitor like Postman does, but that’s not the case. So I went to the next step and manually set the headers.
The Breakthrough: Header Settings
After further digging and reading troubleshooting posts on Cloudflare forums, I decided to manually set the headers under the Advanced settings for the monitor. Within the health monitor set up, I filled out the name, url and type of request. Then I clicked Advanced Settings and created the following header settings for the monitor.
- Host: I set this to the domain that the health check was targeting, for example,
api.parkasoftware.com
. - User-Agent: I set this to
Cloudflare-Health-Check
. - Authorization: Since my API was public I didn’t set this to anything.
- Accept: I set this to
application/json
.
And would’nt you know it, my API health monitor started returning Healthy!
The How-To: Setting Up Headers in Cloudflare
Here are the steps I took to get the Headers set up in my Cloudflare load balancer health monitor.
- Log in to Cloudflare Dashboard: Go to the “Traffic” tab and locate the Load Balancer section. Click edit on the load balancer to edit.
- Click Monitors: Next to your Load Balancer, you’ll see the health check configurations. Click edit. Click Remove if you already have a monitor configured. Then create a new monitor.
- Add Default Options: Fill out the default name, Action and Url.
- Add Headers: Click advanced settings and scroll down to the section where you can add headers. Here, enter the key-value pairs for each header.
- Key:
Host
, Value:api.parkasoftware.com
- Key:
User-Agent
, Value:Cloudflare-Health-Check
- Key:
Authorization
, Value: None or yourBearer access token if required
- Key:
Accept
, Value:application/json
- Key:
- Save and Test: Once all headers are added, save your changes. It’s a good idea to test the health check to make sure it’s working as expected.
Conclusion
The issue was resolved after correctly configuring the Header Settings in Cloudflare’s health check. If you ever find yourself in a similar situation, double-checking these settings could be the key to solving your problem.
Good luck!