Nginx在access.log中打印404登录

问题描述 投票:0回答:1

最近我在

log_not_found
配置中添加了
Nginx
指令。工作正常,可以防止
Nginx
error.log
上打印 404 日志,但仍然在
access.log
上打印 404 日志。

如何禁用

Nginx
404 登录
access.log

示例日志

172.18.xx.xx - - [02/Sep/2024:11:38:00 +0000] "GET /test HTTP/2.0" 404 131 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36" "219.100.xx.xx"

Nginx 配置

http {
    log_format main
        '$remote_addr - $remote_user [$time_local] "$request" '
        '$status $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';

    server {
        listen 443 ssl;
        root /example/path/html;
        log_not_found off;

        access_log /var/log/nginx/access.log main;
        error_log /var/log/nginx/error.log warn;

        location / {
            add_header "Access-Control-Allow-Origin" "*" always;
            try_files $uri =404;
        }
    }
}
nginx
1个回答
0
投票

其实

Nginx
并没有做错什么。每个请求都应该登录
access.log

目前我使用

access_log
完全关闭
location
中的日志。

location /favicon.ico {
    access_log off;
}

除了此解决方法之外,我还向 Nginx GitHub 存储库提交了

功能请求

© www.soinside.com 2019 - 2024. All rights reserved.