Nginx access log. Include only pages

nginx

Now in my access log file too many records, – because images and pages in same file. Is it possible move all images to one file and only php pages to second file?
(filter images and non images files)

server {
    root /home/nginx/site;
    index index.html index.htm index.php;

    access_log /home/nginx/site/_log/site_access.log;
    error_log /home/nginx/site/_log/site_error.log;

    listen              80;
    keepalive_timeout   70;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;
    }

    include /etc/nginx/server.conf.d/php.conf;
}

Best Answer

The access_log directive can be used in different scopes as stated in the documentation :

Context: http, server, location, if in location, limit_except

So for instance it's possible to split locations for static and dynamic content and log what you want where you want.

Another possibility since nginx 1.7.0 is to set up conditional logging directly in the access_log directive using a variable that will evaluate to something different than 0 or an empty string when logging must happen. A configuration sample, given $loggable this variable, would look like the following :

access_log /path/to/access.log if=$loggable;