Вопрос

I need some help to customize my access log on Lighttpd 1.4.28. So far I have been able to modify the configuration to display the date in a strftime(3) format. The default date format is just way too long. Here are the relevant lines from /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"

And here is my access.log entry:

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"

Customizing the date was not hard, but I ran into a problem trying to display request URL while simultaneously using custom 404 pages. I just added

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

to the lighttpd.conf file, and the lighttpd_access.log now contains redirected /error.html, instead of the full url of the request that generated the error.

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"

I have also tried adding %{Request_URI}i, but the log entry was - blank. Anyone knows the correct syntax to use when trying to display the original request URL in conjunction with custom 404 pages?

Это было полезно?

Решение

This isn't an exact fix to your issue but if your goal is just to find out what URLs are broken - use a PHP file instead for your error handler -- you can still redirect to error.html (if you so wish)

lighttpd.conf:

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

error.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");
?>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top