更改 Nginx 日志文件位置
Changing Nginx Log File Location
我无法对要使用的 /etc/nginx/nginx.conf http 块进行任何更改。我从最简单的事情开始——我想将 access.log 的名称修改为其他名称(即 a.log)。这是一个普通的 nginx 安装(还没有自定义配置文件)。这是我所知道的:
- 更改 nginx.conf 头部的值确实会影响配置(将 worker_processes 4 更改为 worker_processes 2 会更改工人的数量)
- 在 nginx.conf 的 http 块中出现语法错误 会导致 nginx 在重启时抛出错误
- 把access_log改成access_log /var/log/nginx/a.log并没有修改日志的位置,nginx实际上是继续记录到/var/log/nginx/access.log
这是我的 nginx.conf 文件的片段:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/a.log;
#....
}
是否像我修改一个被其他配置文件覆盖的 http 块一样简单?感谢您的帮助。
你的access_log不也是在服务器块中定义的吗?查看 nginx/sites-enabled/ 中的默认配置。
在这种情况下,http 块中的值被较低块中的值覆盖。
我无法对要使用的 /etc/nginx/nginx.conf http 块进行任何更改。我从最简单的事情开始——我想将 access.log 的名称修改为其他名称(即 a.log)。这是一个普通的 nginx 安装(还没有自定义配置文件)。这是我所知道的:
- 更改 nginx.conf 头部的值确实会影响配置(将 worker_processes 4 更改为 worker_processes 2 会更改工人的数量)
- 在 nginx.conf 的 http 块中出现语法错误 会导致 nginx 在重启时抛出错误
- 把access_log改成access_log /var/log/nginx/a.log并没有修改日志的位置,nginx实际上是继续记录到/var/log/nginx/access.log
这是我的 nginx.conf 文件的片段:
user www-data;
worker_processes 4;
pid /run/nginx.pid;
events {
worker_connections 768;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/a.log;
#....
}
是否像我修改一个被其他配置文件覆盖的 http 块一样简单?感谢您的帮助。
你的access_log不也是在服务器块中定义的吗?查看 nginx/sites-enabled/ 中的默认配置。 在这种情况下,http 块中的值被较低块中的值覆盖。