Health Checks tutorial
In this tutorial we will show you how to create health checks that will periodically contact your origin servers to make sure they are still working.
We will assume that you are already accustomed to editing and deploying configurations using the web-based configuration application. If you are not familiar with basic editing using the application, please see our Help Guides to learn more before moving forward.
Health checks, while simple in principle, are a little more involved than most other configuration objects. Let's run through the options you have when creating a health check so you have a place to start when working through the tutorial.
- Name - A human-readable identifier for the health check (e.g., "West Coast Origin Check").
- Request - An HTTP method and path to visit on your origin servers when performing the check.
- HTTP Host Header - The HTTP Host Header to set when making the request (e.g. "example.com").
- Expected Response - The HTTP status code the origin servers must respond with for the check to pass (usually "200 OK").
- Check Frequency - How often the origin server is checked with additional parameters that determine if the origin server is up or down. For more information about the additional parameters, see our guide on Health check frequency.
Fastly will periodically check your origin server based on the options chosen. Pay special attention to the HTTP host header. A common mistake is setting the wrong host. If the origin server does not receive a host it expects, it may issue a 301 or 302 redirect causing the health check to fail. Also, Varnish requires the origin server receiving the health check requests to close the connection for each request. If the origin server does not close the connection, health checks will time out and fail.
If an origin server is marked unhealthy due to health checks, Fastly will stop attempting to send requests to it. If all origin servers are marked unhealthy, Fastly will attempt to serve stale. If no stale object is available, a 503 will be returned to the client.
Creating a Health Check
Log in to the Fastly application and click the configure tab (wrench icon).
From the Service menu, select the appropriate service and then click the blue Configure button. The main controls for your selected service appear.
Click Hosts from the section list on the left. The Hosts window appears.
In the Health Checks area at the bottom of the page, click the green New button. The New Health Check window appears.
Fill out the fields in the New Health Check window. For more information, review the field descriptions in the Overview section.
Click the Create button to create the health check.
Your new health check will now appear in the list of checks.
Assigning a Health Check
Health checks do nothing on their own, but they can be added as a special parameter to an origin server in your configuration.
Edit one of your existing origin servers by clicking the gear to the right of the origin server's name, and then selecting the Edit option.
From the Health Check menu, select the health check you just created.
Fastly will now use the health check to monitor the selected origin server.