This article is intended to provide multiple options to perform health checks at the Apache HTTPD level to ensure that traffic is routed to the healthy Liferay instance. Please note that even though the configuration options speak about Liferay as the load balanced application, these can be applied to any environment that is being fronted and loadbalanced by the Apache HTTPD application.

For the health checks to work successfully, the following modules need to be enabled at the Apache HTTPD level.

  1. proxy_hcheck_module
  2. mod_watchdog
  3. mod_proxy_balancer
  4. mod_lbmethod_byrequests (only needed if Apache v2.4 and above)

Configuration example

Here’s an example snippet that would be a part of configuration followed by the explanation. We have included multiple examples here to illustrate the various options available for administrators to configure health checks.

ProxyHCExpr ok234 {%{REQUEST_STATUS} =~ /^[234]/}
ProxyHCExpr gdown {%{REQUEST_STATUS} =~ /^[5]/}
ProxyHCExpr in_maint {hc('body') !~ /Under maintenance/}


  BalancerMember http://host1:8080/  hcmethod=GET hcexpr=in_maint hcuri=/status.html
  BalancerMember http://host2:8080/ hcmethod=HEAD hcexpr=ok234 hcinterval=10
  BalancerMember http://host3:8080/ hcmethod=TCP hcinterval=5 hcpasses=2 hcfails=3
  BalancerMember http://host4:8080/


ProxyPass "/" "balancer://liferay"
ProxyPassReverse "/" "balancer://liferay"


  • For the configuration listed above, the following section explains the configuration in detail:
  • http://host1:8080/ is health-checked by sending a GET /status.html request to that server and seeing that the returned page does not include the string Under maintenance. If it does, that server is put in health-check fail mode, and disabled. This dynamic check is performed every 30 seconds, which is the default.
  • http://host2:8080/ is checked by sending a simple HEAD request every 10 seconds and making sure that the response status is 2xx, 3xx or 4xx.
  • http://host3:8080/ is checked every 5 seconds by simply ensuring that the socket to that server is up. If the backend is marked as “down” and it passes two health checks, it will be re-enabled and added back into the load balancer. It takes three back-to-back health check failures to disable the server and move it out of the rotation.
  • Finally, http://host4:8080/ is not dynamically checked at all.

Summary

End-user experience can make or break the usage of a website. In the cases of unintended downtimes or where a downtime isn’t handled well, user attrition can happen very quickly.

With the health check module provided by Apache HTTPD, end-user experience of using the website during code deployments or a downtime instance can be improved dramatically without requiring a lot of plumbing in place or infrastructure changes needed.

If you have questions on how you can best leverage our experience, would like further examples and/or need help with your Liferay DXP implementation, please engage with us via comments on this blog post, or reach out to us.

Additional Resources

You can also continue to explore Liferay DXP by checking out the following posts.
The Top 10 New Features in Liferay DXP 7 (functional perspective)
Top 5 New Features in Liferay DXP UI Development
Creating JAX-RS REST Services in Liferay DXP (development perspective)
Top 5 DevOps Features in Liferay DXP (devops perspective)

Share This