How to log server_name in access_log.

Brice Figureau brice+nginx at
Tue Oct 2 13:16:43 MSD 2007

On Tue, 2007-10-02 at 10:59 +0200, Matteo Niccoli wrote:
> Hi,
> I have a single access_log for each vhost configured in nginx. I tried to
> find in web, google, newsgroup, and so on, but i'm not able to log, as
> first field of log row, the server_name. Actually nginx logs as first field
> the ip client. I need to log the server_name. With apache I use this:
> LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
> \"%{User-Agent}i\" VLOG=%{VLOG}e"

That's easy, define in your http {} block:
    log_format vhost '$server_name $remote_addr - - [$time_local] '
                   '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" ';

and in your servers blocks:
   access_log /path/to/logfile vhost;

Brice Figureau <brice+nginx at>

More information about the nginx mailing list