Nginx writing separately to two different logs

5,007

It is common practice to define a seperate logfile for each vhost. Without knowing your config, I assume, that the main nginx.conf has defined a default log file. It will log any request that is not matching any of the vhosts that might be configured. I assume that sites-enabled/mysite is a vhost that is using name-based virtual host (in Apache speech this is called 'NameVirtualHost'. So every request for this vhost will go into the configured log file for that vhost, any other request, that hits the nginx server (e. g. by calling the IP address instead of the hostname) will (most likely) not match the vhost and therefor will hit the default configuration and it's associated log file.

You might wanna have a look at: http://nginx.org/en/docs/http/server_names.html and http://wiki.nginx.org/HttpLogModule

Share:
5,007

Related videos on Youtube

benwad
Author by

benwad

Updated on September 18, 2022

Comments

  • benwad
    benwad over 1 year

    I've recently taken over as Sysadmin of a site, and the first thing I noticed was that there were two Nginx access_logs defined: access.log and access_new.log, and they were both being written to.

    Looking around the configuration I could see that in the http section of nginx.conf it defined access.log as the access_log, and in the sites-enabled/mysite configuration it defined access_new.log as the log. I am curious as to why both of these logs would b written to: surely the configuration for the site would override the default config?