简体   繁体   English

更改Nginx日志文件位置

[英]Changing Nginx Log File Location

I can't get any changes in the /etc/nginx/nginx.conf http block to be used. 我无法在/etc/nginx/nginx.conf http块中使用任何更改。 I'm starting with the simplest thing - I want to modify the name of access.log to something else (ie a.log). 我从最简单的事情开始-我想将access.log的名称修改为其他名称(即a.log)。 It is a vanilla nginx install (no custom config files yet). 这是普通的nginx安装(尚无自定义配置文件)。 Here's what I know: 这是我所知道的:

  • changing a value in the head of nginx.conf does affect the configuration (changing worker_processes 4 to worker_processes 2 does change the # of workers) 更改nginx.conf开头的值确实会影响配置(将worker_processes 4更改为worker_processes 2会更改worker的数量)
  • Making a syntax error in nginx.conf's http block does cause nginx to throw an error on restart 在nginx.conf的http块出现语法错误确实会导致nginx在重新启动时引发错误
  • Changing access_log to access_log /var/log/nginx/a.log does not modify the location of the log, and nginx in fact continues logging to /var/log/nginx/access.log 将access_log更改为access_log /var/log/nginx/a.log不会修改日志的位置,并且nginx实际上会继续记录到/var/log/nginx/access.log

Here is a snippet of my nginx.conf file: 这是我的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;
        #....
}

Is it something as simple as I'm modifying an http block that gets overwritten by some other config file? 它就像修改一个被其他配置文件覆盖的http块一样简单吗? Thanks for the help. 谢谢您的帮助。

Isn't your access_log also defined in a server block ? 您的access_log是否也在服务器块中定义? Have a look at the default config in nginx/sites-enabled/. 看看nginx / sites-enabled /中的默认配置。 In this case the value in http block is overwritten by the one in the lower block. 在这种情况下,http块中的值将被较低的块中的值覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM