V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
lemonda
V2EX  ›  问与答

如何对 Nginx rewrite 后的请求禁止日志?

  •  
  •   lemonda · 2021-12-08 03:29:28 +08:00 · 751 次点击
    这是一个创建于 842 天前的主题,其中的信息可能已经有所发展或是发生改变。
    
    location ~* \.(ico|gif|bmp|jpg|jpeg|png|webp|swf|js|css|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm) {
            expires 30d;
            access_log off;
            log_not_found off;
    }
    
    

    本来已经禁止了日志,但是由于要对其中的 CSS 和 JS 进行动态压缩,加了类似下面的 rewrite

    rewrite ^/cache/minify/ /index.php last;
    

    导致 /cache/minify/818c0.js 这样的请求又被 log

    请问有什么方法可以对 rewrite 后的请求禁止日志?

    2 条回复    2021-12-09 18:08:49 +08:00
    ysc3839
        1
    ysc3839  
       2021-12-08 03:46:43 +08:00 via Android   ❤️ 1
    说个题外话,像这种“匹配任意前缀”然后把请求交给某个后端处理的情况是可以而且应该用 location + try_files 实现的。
    估计改成
    location /cache/minify/ {
    access_log off;
    log_not_found off;
    try_files /index.php;
    }
    就行了。
    lemonda
        2
    lemonda  
    OP
       2021-12-09 18:08:49 +08:00
    @ysc3839
    果然可以,谢谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1185 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:10 · PVG 07:10 · LAX 16:10 · JFK 19:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.