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

Apache 服务,日志部分配置不能正确写入的问题,请问是哪里出了问题?

  •  
  •   qazwsxkevin · 119 天前 · 456 次点击
    这是一个创建于 119 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # 设置默认首页
    DirectoryIndex index.html
    
    LogFormat "%{%Y-%m-%d %H:%M:%S}t | %a | %h | %m | %U | %{User-agent}i" custom_log_format
    
    # 第 1 路日志,只记录访问/help.html ,使用日志格式输出到/opt/apache2/log/help.log ,1 天 1 个日志文件作为切割
    SetEnvIf Request_URI "^/sale\.html$" help_page
    CustomLog "|/usr/bin/rotatelogs /opt/apache2/log/help.log.%Y-%m-%d 86400" custom_log_format env=help_page
    
    # 第 2 路日志,只记录访问/index.html ,使用以上日志格式输出到/opt/apache2/log/index.log ,1 天 1 个日志文件作为切割
    SetEnvIf Request_URI "^/index\.html$" index_page
    CustomLog "|/usr/bin/rotatelogs /opt/apache2/log/index.log.%Y-%m-%d 86400" custom_log_format env=index_page
    
    # 第 3 路日志,记录除了访问(/help.html 、/index.html)这 2 个页面以外的全部记录,使用日志格式输出到/opt/apache2/log/another.log ,1 天 1 个日志文件作为切割
    SetEnvIf Request_URI "^/(sale\.html|index\.html)$" dontlog
    CustomLog "|/usr/bin/rotatelogs /opt/apache2/log/another.log.%Y-%m-%d 86400" custom_log_format env=!dontlog
    

    以上 3 路条件都做了测试,
    现象是: 1 、help.html 的记录完全正常 2 、访问 index.html 的记录,全部写入到 another.log 了.... 3 、而 index.log ,连创建文件都没有产生,第 2 路没有起效

    请问,这日志部分是在哪里出了问题?

    这个配置问过 chatgpt 3.5 ,回答是顺序问题,我也试着调整过次序,应该不是这个问题? 是逻辑问题?

    1 条回复
    qazwsxkevin
        1
    qazwsxkevin  
    OP
       119 天前
    问题解决了,首页不是"/index.html"
    setenvif 匹配的首页是“/“,
    所以正确的书写,是:
    SetEnvIf Request_URI "^/$" index_page
    临时搭个 apache 玩玩,就这样完事了。。。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2644 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 114ms · UTC 15:15 · PVG 23:15 · LAX 08:15 · JFK 11:15
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.