0

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;
}
2

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;
4
  • But why I see this error message: Restarting nginx: nginx: [emerg] "invalid parameter if=$loggable" I tried this code link – SPnova Feb 19 '15 at 21:15
  • @SPnova Nginx version ? – Xavier Lucas Feb 19 '15 at 21:42
  • "nginx -V": * nginx-extras * nginx-full * nginx-light * nginx-naxsi ; Version nginx/1.5.3 – SPnova Feb 20 '15 at 5:31
  • 2
    Read answers carefully. if flag exists since version 1.7.0, you've got 1.5.3. So you have only option to use different locations – Alexey Ten Feb 20 '15 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.