Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx - Exclude specific file or folder from logging to access.log

Tags:

logging

nginx

I'm using an access and error log in Nginx.

I have extremely large number of requests for stats which take up too much storage space in access.log and are not required.

Is it possible to exclude a specific file or folder from logging to access.log?

I would like to exclude all requests to /stats/

server {
    listen  80 default_server;
    listen  443 ssl default_server;
    server_name ***.co.uk www.***.co.uk;

    root  /var/www/***/html;
    index index.html index.php;

    access_log /var/www/***/log/access.log;
    error_log /var/www/***/log/error.log;
}    
like image 935
Asa Carter Avatar asked Mar 12 '23 06:03

Asa Carter


1 Answers

You can do this if you know which location block or server is handling the request for stats. Just add the directive access_log off; to the server or location block in which you want this disabled.

--Edit--

Add this location to your server block:

location /stats/ {
    try_files $uri $uri/ =404;
    access_log off;
}
like image 196
Keenan Lawrence Avatar answered Apr 08 '23 16:04

Keenan Lawrence