Forum: NGINX Multiple access_log directives in different contexts

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Sen H. (Guest)
on 2009-01-17 18:11
I have a traffic log directive in my http block:

http
{
  # Traffic log
  log_format traffic $time_local | $server_name | $request_length |
$bytes_sent;
  access_log /var/log/nginx/traffic.log traffic;
[…]
}

This works just fine except for virtual hosts that have a custom
access_log directive defined.
Traffic is not showing for these domains.

server
{
  access_log /var/www/example.com/data/logs/nginx.access.log;
  error_log /var/www/example.com/data/logs/nginx.error.log error;
[…]
}

How can I use global traffic log and custom access log together?
Igor S. (Guest)
on 2009-01-17 19:12
(Received via mailing list)
On Sat, Jan 17, 2009 at 05:11:32PM +0100, Sen Haerens wrote:

>
> This works just fine except for virtual hosts that have a custom
> access_log directive defined.
> Traffic is not showing for these domains.
>
> server
> {
>   access_log /var/www/example.com/data/logs/nginx.access.log;
>   error_log /var/www/example.com/data/logs/nginx.error.log error;

+   access_log /var/log/nginx/traffic.log traffic;
Maxim D. (Guest)
on 2009-01-17 19:12
(Received via mailing list)
Hello!

On Sat, Jan 17, 2009 at 05:11:32PM +0100, Sen Haerens wrote:

>
>
> How can I use global traffic log and custom access log together?

There is no "global" logs in nginx, only "local" ones, either
explicitly defined or inhereted from previous level.

The access_log directive, as all array-type directives in nginx
config, will ignore inherited values if defined at certain level.
I.e. in configuration

http {
    access_log log1;

    server {
        server_name  server1;
    }

    server {
        server_name  server2;
        access_log   log2;
        ...
    }
}

only server1 will have logging set to log1, while server2 will
have logging set to log2.  If you want server2 to write log into
both log1 and log2 you should say this explicitly, i.e.

    server {
        server_name  server2;
        access_log   log1;
        access_log   log2;
        ...
    }

In you case you should explicitly add

    access_log ... traffic;

to all servers which define their own logging.

Maxim D.
Sen H. (Guest)
on 2009-01-18 00:50
All fixed!
Thank you for your detailed responses.
This topic is locked and can not be replied to.