为什么写指令 access_log on 两次实际上关闭了日志?
Why writing the directive access_log on twice actually turn off log?
以下nginx.conf可以说明问题
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!
...
}
...
}
所以写两遍access_log on;
居然关掉了日志。这是为什么 ?我不禁想知道这是一个错误吗?
谢谢
----更新----
原来只有 access_log off
指令,没有 access_log on
(不知道为什么我首先得到它 :$)所以当我写 access_log on
时,日志是写入了一个名为 "on" 的文件,而不是我预期的 /var/log/nginx/access.log
。所以我想为什么没有日志?! :$
这是预期的行为。来自 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.
因此,如果您不将 access_log on;
放入 location / {
中,那么您会得到两个日志文件,因为 server
上下文中的日志文件将适用。相反,如果将 access_log on;
放在 location / {
中,则外部作用域的访问日志配置将不适用。
以下nginx.conf可以说明问题
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!
...
}
...
}
所以写两遍access_log on;
居然关掉了日志。这是为什么 ?我不禁想知道这是一个错误吗?
谢谢
----更新----
原来只有 access_log off
指令,没有 access_log on
(不知道为什么我首先得到它 :$)所以当我写 access_log on
时,日志是写入了一个名为 "on" 的文件,而不是我预期的 /var/log/nginx/access.log
。所以我想为什么没有日志?! :$
这是预期的行为。来自 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.
因此,如果您不将 access_log on;
放入 location / {
中,那么您会得到两个日志文件,因为 server
上下文中的日志文件将适用。相反,如果将 access_log on;
放在 location / {
中,则外部作用域的访问日志配置将不适用。