减少健康检查日志记录

Nat*_*rot 5 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 ...
         }
    }
}
Run Code Online (Sandbox Code Playgroud)

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

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

由于我要求error该位置内部的级别/health,因此我认为我不会看到此信息级别消息。我怎样才能让它安静下来?

小智 4

位置不应嵌套。

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

}
Run Code Online (Sandbox Code Playgroud)