Search code examples
djangoamazon-web-servicesnginxamazon-elb

How to setup health check page in django


I have a webapp which required authentication to access any page of it. But for my ELB to work I have to setup health-check page for ELB so that ELB discover django app.

This page should return HTTP 200 and no auth required. How do I setup this with django/nginx world.


Solution

  • NOT RECOMMENDED - this was a quick and dirty way to get Django up and running with ELB, but in most cases a health check response should be returned directly from your application code. See the rest of the answers for a better solution.


    This is something better handled by nginx, so the fact that it's serving a django app should make no difference.

    You will first need to configure ELB's health check to ping a specific URL of your instance, say /elb-status. You can follow the instructions here: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-healthchecks.html#update-health-check-config

    After that, all you need to do is set up nginx to always send back an HTTP 200 status code. You can add something like this to your server block in nginx.conf:

    location /elb-status {
        access_log off;
        return 200;
    }
    

    See this answer for more details.