【问题标题】:How to set apache2.4 custom log如何设置apache2.4自定义日志
【发布时间】:2019-10-28 11:19:10
【问题描述】:

我找不到如何使用 Apache2.4 为我的网站设置自定义日志位置。

<IfModule mod_ssl.c>
  <VirtualHost *:443>
   ....
   php_value error_reporting 2047
   php_flag magic_quotes_gpc off
   php_flag short_open_tag off

   DirectoryIndex index.php index.html

   <Directory /var/www/ablog>
     Options FollowSymLinks
     AllowOverride All

     Order allow,deny
     Allow from all
    </Directory>

    CustomLog ./logs/blog_log common

  </VirtualHost>
</IfModule>

这将导致以下错误:

(2)No such file or directory: AH02297: Cannot access directory '/etc/apache2/logs/' for log file './logs/blog_log' defined at /var/www/ablog/vhost.conf:31

【问题讨论】:

  • /etc/apache2/logs 是否存在,您运行 apache 的用户是否可以写入 - 您是否以 root 身份运行它?我可能会尝试创建 /etc/apache2/logs/logs/ 以防万一它以某种方式以两个 /logs/ 结尾,但我猜不会。您也可以尝试为 CustomLog 提供一个绝对路径,指向您绝对可以编写的某个位置,例如/tmp/blog_log,并查看创建文件的所有者和权限。
  • 存在且可写。但是这里没有任何来自该站点的内容。我看到了,这纯粹是权限问题/文件不存在。我会尝试这个想法,谢谢。
  • 绝对路径有效,如果您想添加正确答案,请这样做。

标签: apache logging


【解决方案1】:

例如,以下两组指令的效果完全相同:

带有格式昵称的CustomLog

LogFormat "%h %l %u %t \"%r\" %>s %b" 常见 CustomLog "logs/access_log" 通用

带有显式格式字符串的CustomLog

CustomLog "logs/access_log" "%h %l %u %t \"%r\" %>s %b"

详情在这里: http://httpd.apache.org/docs/current/mod/mod_log_config.html

【讨论】:

  • 这似乎没有解决 OP 的特定错误。
  • 你的conf显示CustomLog ./logs/blog_log common改成CustomLog "./logs/blog_log common"
  • 再次感谢 Enzamam:CustomLog takes two or three arguments, a file name, a custom log format string or format name, and an optional "env=" or "expr=" clause (see docs)
猜你喜欢
  • 2019-04-04
  • 2018-02-08
  • 1970-01-01
  • 1970-01-01
  • 2014-07-22
  • 2012-10-03
  • 1970-01-01
  • 2018-09-17
  • 2021-12-12
相关资源
最近更新 更多