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

120 天前
 qazwsxkevin
# 设置默认首页
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 ,回答是顺序问题,我也试着调整过次序,应该不是这个问题? 是逻辑问题?

456 次点击
所在节点    问与答
1 条回复
qazwsxkevin
119 天前
问题解决了,首页不是"/index.html"
setenvif 匹配的首页是“/“,
所以正确的书写,是:
SetEnvIf Request_URI "^/$" index_page
临时搭个 apache 玩玩,就这样完事了。。。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1044881

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX