Reputation: 12445
The following nginx.conf can show the peoblem
server {
listen 80;
access_log /var/log/nginx/access.log combined;
access_log on;
...
location / {
access_log on; # write it the second time actually turn off the log!
...
}
...
}
So write access_log on;
twice actually turn off the log. Why is that ? I can't help wondering is it a bug ?
Thanks
---- update ----
It turned that there is only access_log off
directive, no access_log on
(no idea why I got that in the first place :$) so when I wrote access_log on
the log was wrote to a file called "on", not /var/log/nginx/access.log
as I expected. So I thought why there is no log ?! :$
Upvotes: 0
Views: 855
Reputation: 9875
This is the expected behavior. From NGINX blog:
Access Logs Are Not Inherited
Access log settings do not stack or inherit; an access_log directive in one context overrides (replaces) access logs declared in parent contexts.
So if you don't put access_log on;
in location / {
then you get two log files because the ones in server
context will apply. Contrary, if you put access_log on;
in location / {
then the outer scope's access log configuration will not apply.
Upvotes: 1