如何在Django中设置运行状况检查页面 [英] How to setup health check page in django

查看:95
本文介绍了如何在Django中设置运行状况检查页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Webapp,需要进行身份验证才能访问它的任何页面.但是要使我的ELB正常工作,我必须为ELB设置运行状况检查页面,以便ELB发现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.

此页面应返回HTTP 200,并且无需身份验证.如何使用django/nginx world进行设置.

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

推荐答案

不推荐-这是让Django与ELB一起启动并运行的一种快速而肮脏的方法,但是在大多数情况下,应返回运行状况检查响应直接从您的应用程序代码.请参阅其余答案,以获得更好的解决方案.

这是nginx更好地处理的,因此它正在为Django应用程序提供服务这一事实应该没什么区别.

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

您首先需要配置ELB的运行状况检查以ping您实例的特定URL,例如/elb-status.您可以按照此处的说明进行操作: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/elb-healthchecks.html#update-health-check-config

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

在那之后,您需要做的就是设置nginx,使其始终发送回HTTP 200状态代码.您可以在nginx.conf中的server块中添加类似的内容:

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;
}

请参见此 answer 有关更多详细信息.

See this answer for more details.

这篇关于如何在Django中设置运行状况检查页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆