【问题标题】:How exclude .json extension from nginx logs如何从 nginx 日志中排除 .json 扩展名
【发布时间】:2022-12-18 12:04:07
【问题描述】:

我想排除所有这些扩展的日志woff, jpg, jpeg, png, gif, ico, css, js, json

default.conf我添加了这些位置规则

location ~* \.(woff|jpg|jpeg|png|gif|ico|css|js|json)$ {
        access_log off;
    }

除了json,所有扩展都被排除在日志之外

我试过这样的单独规则

location ~* \.(json)$ {
        access_log off;
    }

或者

location ~ \.json$ {
        access_log off;    
    }

无论如何我仍然可以在日志中看到 json 文件

在同一个 default.conf 中,我有另一个 json 扩展规则

location ~* \.(json)$ {
        add_header Cache-Control "must-revalidate";
    }

这可能是问题吗? 知道如何解决吗?

【问题讨论】:

    标签: nginx nginx-config


    【解决方案1】:

    通过在 json 扩展名的第一个位置添加 access_log off; 规则来修复

    location ~* .(json)$ {
            add_header Cache-Control "must-revalidate";
            access_log off;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-22
      • 2020-11-08
      • 2016-11-08
      • 2016-07-22
      • 2014-03-21
      • 1970-01-01
      相关资源
      最近更新 更多