29.2 Confguring Error Logs

Problem

You need to configure error logging to better understand issues with

your NGINX server.

问题

需要更深入的定位 NGINX 服务器问题,以配置错误日志。


Solution

Use the error_log directive to define the log path and the log level:

error_log /var/log/nginx/error.log warn;

The error_log directive requires a path; however, the log level is

optional. This directive is valid in every context except for if state‐

ments. The log levels available are debug, info, notice, warn, error,

crit, alert, or emerg. The order in which these log levels were

introduced is also the order of severity from least to most. The

debug log level is only available if NGINX is configured with the --

with-debug flag.

解决方案

使用 error_log 指令定义错误日志目录及记录错误日志的等级:

error_log /var/log/nginx/error.log warn;

error_log 指令配置时需要一个必选的日志目录和一个可选的错误等级选项。

除 if 指令外,error_log 指令能在所有的上下文中使用。错误日志等级包括:

debug、info、notice、warn、error、crit、alert 和 emerg。给出的日志

等级顺序就是记录最小到最严谨的日志等级顺序。需要注意的是 debug 日志

需要在编译 NGINX 服务器时,带上 --with-debug 标识才能使用。


Discussion

The error log is the first place to look when configuration files are

not working correctly. The log is also a great place to find errors

produced by application servers like FastCGI. You can use the error

log to debug connections down to the worker, memory allocation,

client IP, and server. The error log cannot be formatted. However, it

follows a specific format of date, followed by the level, then the mes‐

sage.

结论

请牢记当服务器配置出错时,首先需要查看错误日志以定位问题。当然,错误日志

也是定温应用服务器(如 FastCGI 服务)的利器。通过错误日志,我们可以调试 worder

进程连接错误、内存分配、客户端 IP 和 应用服务器等问题。错误日志格式虽然不支

持自定义日志格式;但是,它同样记录当前时间、日志等级和具体信息等数据。

results matching ""

    No results matching ""