禁用登录Nginx的特定请求 [英] Disable logging in nginx for specific request
本文介绍了禁用登录Nginx的特定请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图基于请求URI在Nginx日志中忽略"或重定向某些请求.
I'm trying to "ignore" or redirect certain request in the nginx log based on the request URI.
到目前为止,我有这个:
So far I have this:
server {
listen 80;
#...
access_log /var/log/nginx/site.access;
error_log /var/log/nginx/site.error info;
#...
try_files $uri @app
location = /lbcheck.html {
access_log off;
log_not_found off;
try_files $uri @app;
}
location @app {
proxy_redirect off;
proxy_pass http://unix:/tmp/site.unicorn.sock;
#...
}
}
基本上,我希望代理的@app响应对/lbcheck.html
的请求,但我不希望它登录/var/log/nginx/site.access;
Basically I want the proxied @app to respond to the request for /lbcheck.html
but I don't want it logged in /var/log/nginx/site.access;
我知道我可以用location @app
中的if ($uri = /lbcheck.html) { access_log off; }
来做到这一点,但是如果它是邪恶的,那么我就不想使用它们.
I know i can do it with a if ($uri = /lbcheck.html) { access_log off; }
in location @app
but if's are evil, so I don't want to use them.
推荐答案
您可以使用条件记录进行此操作.看起来像
map $request $loggable {
~*lbcheck\.html 0;
default 1;
}
access_log /path/logs/name.log if=$loggable;
这篇关于禁用登录Nginx的特定请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文