How to Disable access.log in nginx (Server-Wide or for Part of a Site)
Question: how do you disable access.log in nginx?
Answer: put access_log off; in the nginx configuration and reload nginx.
On a busy server access.log grows fast and writes every request to disk. If you don’t need the request log (or need it only for part of the site), you can turn it off entirely or selectively.
Disable access.log for the whole server
In nginx.conf, in the http { … } block:
access_log off;
Test the configuration and reload nginx:
nginx -t nginx -s reload
Disable it for one site or section only
The directive also works inside a specific site’s server { … } block or even a location. For example, to stop logging requests for images, CSS and JS:
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
access_log off;
expires 30d;
}
It’s also useful to keep the error log free of requests for missing favicon.ico and robots.txt:
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
What about error_log?
That doesn’t work for the error log: error_log off; doesn’t disable it — it creates a file named “off”. If you really don’t need errors, send them nowhere and keep only critical ones:
error_log /dev/null crit;
But it’s better not to disable error_log completely — without it, it’s hard to tell why a site stopped working.
