减少日志记录以进行健康检查

时间:2016-08-30 20:01:57

标签: nginx

我希望Nginx在进行健康检查时记录较少,但我无法像预期的那样使其静音。我想帮助找到配置中的错误。

我的nginx配置如下所示:

daemon off;
worker_processes 1;
error_log /dev/stderr debug;

events {
    worker_connections 1024;
}
http {
    access_log /dev/stdout;
    resolver_timeout 10s;

    upstream api {
        server api.local;
    }

    server {
        listen 80;
        location / {
            proxy_pass http://api;
            location /health {
                # health checks are frequent and boring, so we avoid logging them
                access_log off;
                error_log /dev/stderr error;
                proxy_pass http://api;
             }
             location /users {
                proxy_pass http://api;
                # other stuff ...
             }
             # other locations ...
         }
    }
}

当Kubernetes用livenessProbe探测它时,我会得到一系列像

这样的行
  

2016/08/30 19:50:32 [info] 7#0:* 1等待请求时客户端关闭连接,客户端:10.2.29.0,服务器:0.0.0.0:80

由于我在error位置内要求/health级别,我以为我不会看到此信息级别的消息。我怎么能让它沉默?

1 个答案:

答案 0 :(得分:1)

位置不应嵌套。

server 
{

location / {
            proxy_pass http://api;
         }

location /health {
# health checks are frequent and boring, so we avoid logging them
                access_log off;
                error_log /dev/stderr error;
                proxy_pass http://api;
         }

location /users {
                proxy_pass http://api;
                # other stuff ...
         }

}