I'm currently configuring a high availability setup using Keepalived to manage failover between Nginx servers. As part of this setup, I need to implement a health check script to verify that Nginx is running and that the backend sites served by Nginx are reachable.
The current script I have in place uses killall -0 nginx
to check if the Nginx process is running. However, I'm unsure if this is the most effective method for ensuring Nginx functionality and backend site reachability.
Would using a script that employs curl to send a HEAD request to the Nginx server be a better approach? Here's the modified script I'm considering:
vrrp_script check_nginx {
script "/usr/bin/curl --silent --head --fail http://localhost:80/ || exit 1"
interval 2
}
Is this alternative method more robust and reliable for verifying Nginx functionality and backend site reachability within a Keepalived script? Are there any potential drawbacks or better alternatives that I should consider? Any insights or recommendations would be greatly appreciated. Thank you!