【问题标题】:Changing Nginx Log File Location更改 Nginx 日志文件位置
【发布时间】:2015-04-15 15:03:36
【问题描述】:

我无法对要使用的 /etc/nginx/nginx.conf http 块进行任何更改。我从最简单的事情开始——我想将 access.log 的名称修改为其他名称(即 a.log)。这是一个普通的 nginx 安装(还没有自定义配置文件)。以下是我所知道的:

  • 更改 nginx.conf 头部的值确实会影响配置(将 worker_processes 4 更改为 worker_processes 2 确实会更改 worker 的数量)
  • 在 nginx.conf 的 http 块中出现语法错误确实会导致 nginx 在重启时抛出错误
  • 将 access_log 改为 access_log /var/log/nginx/a.log 并不会修改日志的位置,nginx 实际上会继续记录到 /var/log/nginx/access.log

这是我的 nginx.conf 文件的 sn-p:

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 块一样简单?感谢您的帮助。

【问题讨论】:

  • 试试“grep -r /var/log/nginx/access.log /etc/nginx”和“grep -r include /etc/nginx”。
  • “香草”安装可能会因您使用的发行版而异,但它可能是像 /etc/nginx/conf.d/default 这样的文件,用于指定默认虚拟主机的工作方式。跨度>
  • "grep -r /var/log/nginx/access.log /etc/nginx" 什么也不返回,"grep -r include /etc/nginx" 返回"/etc/nginx/nginx.conf : 包括 /etc/nginx/mime.types; /etc/nginx/nginx.conf: #include /etc/nginx/naxsi_core.rules; /etc/nginx/nginx.conf: 包括 /etc/nginx/conf.d/ *.conf; /etc/nginx/nginx.conf: 包括 /etc/nginx/sites-enabled/*;"
  • 感谢您的意见。这是一个 ubuntu 发行版。 conf.d 中没有文件。
  • 也许你有一个 /etc/nginx/sites-enabled/default 文件呢?

标签: nginx


【解决方案1】:

您的 access_log 不是也定义在服务器块中吗?查看 nginx/sites-enabled/ 中的默认配置。 在这种情况下,http 块中的值被较低块中的值覆盖。

【讨论】:

  • 谢谢!我需要将更改放在服务器块中的访问日志中。要更改日志的格式,我必须在 nginx.conf http 块中添加一个 log_format 行,现在一切都按预期工作了。
猜你喜欢
  • 2018-10-12
  • 2018-02-07
  • 2015-07-22
  • 1970-01-01
  • 2016-07-06
  • 2019-04-18
  • 2016-07-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多