1

我需要一些帮助来自定义我在 Lighttpd 1.4.28 上的访问日志。到目前为止,我已经能够修改配置以strftime(3)格式显示日期。默认日期格式太长了。以下是来自的相关行/etc/lighttpd/lighttpd.conf

accesslog.format = "%s [%{%d%b-%H:%M}t] %h      %b %U   *       %{From}i|%{Via}i|%{Referer}i    *
accesslog.filename = "/web/lighttpd_access.log"

这是我的 access.log 条目:

404 [24Aug-16:55] 98.68.178.112 345 /phpMyAdmin/scripts/setup.php   *   -|-|-   *   "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1"

自定义日期并不难,但我在尝试显示请求 URL 的同时使用自定义 404 页面时遇到了问题。我刚刚添加

server.error-handler-404 = "/error.html"

lighttpd.conf文件,lighttpd_access.log现在包含 redirected /error.html,而不是生成错误的请求的完整 url。

200 [24Aug-16:06] 98.68.178.112 1 /error.html   *   -|-|-   *   "Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1"

我也尝试过添加%{Request_URI}i,但日志条目是-空白的。任何人都知道尝试将原始请求 URL 与自定义 404 页面结合使用时使用的正确语法吗?

4

1 回答 1

1

这不是对您的问题的确切解决方案,但如果您的目标只是找出哪些 URL 被破坏 - 使用 PHP 文件代替您的错误处理程序 - 您仍然可以重定向到 error.html(如果您愿意)

lighttpd.conf:

server.error-handler-404 = "/error.php"

错误.php:

<?
$brokenpath = $_SERVER["REQUEST_URI"]."\n";
$out = fopen("/foo/bar/404.txt", "a"); // save broken urls here
fputs($out, $brokenpath);`
fclose($out);
header("Location: http://domain.com/error.html");
?>
于 2011-12-11T02:22:14.223 回答