Page Discussion History


Separating error logs per virtual host

When you have multiple virtual hosts, it makes sense to keep a separate error logs for all. Virtual hosts can be completely independent, and even managed by different admins. Therefore, each should have its own access and error log. (However, lighttpd's author refuses to implement this feature ).

Here is a configuration example for separate error logging per virtual host. Note that the error_log directive has different default values depending on the section it appears in. This means that you have to explicitly set the error logging level in the server {...} block.

error_log logs/main_error.log;
events {
  worker_connections 1024;
http {
  error_log logs/http_error.log error;
  server {
    server_name one.org;
    access_log logs/one.access;
    error_log logs/one.error error;
  server {
    server_name two.org;
    access_log logs/two.access;
    error_log logs/two.error error;

This way, a request for one.org/nonexistent.html file will output the following error in logs/one.error:

2009/01/01 19:45:44 [error]  29874#0: *98 open() "/var/www/one/nonexistent.html" failed (2: No such file or directory), client:, server: one.org, request: "GET /nonexistent.html HTTP/1.1", host: "one.org"