打开nginx调试 Tuesday, July 8, 2014 6:10 PM 打开nginx调试 2011年9月10日 admin 发表评论 阅读评论 3715 次浏览 请关注最新修正合订: http://lenky.info/ebook/

这一系列的文章还是在09年写的,存在电脑里很久了,现在贴出来。顺序也不记得了,看到那个就发那个吧,最近都会发上来。欢迎转载,但请保留链接:http://lenky.info/,谢谢。

第一:打开debug模式进行编译,简单操作如下:

sudo ./configure –with-debug

sudo make

sudo make install

应注意–with-debug选项,记得打开,不光这篇文章,后面的其它文章都在打开它的基础上进行的讨论。 第二:合理设置配置文件:

error_log logs/error.log debug;

debug级别会记录所有信息,这点在源文件

ngx_log.c

内的函数

ngx_set_error_log_levels()

的最后几行代码:

} else if (log->log_level == NGX_LOG_DEBUG) {

log->log_level = NGX_LOG_DEBUG_ALL;

}

可以看到,如果设置为debug级别,则程序自动扩为NGX_LOG_DEBUG_ALL,

以记录所有的打印信息。

第三:如果觉得debug把所有的信息都记录下来,不便于定位信息,则可以再加一条配置信息,以缩减记录信息的数目:

error_log logs/error.log notice;

error_log logs/error.log debug_http;

这样,就仅仅记录与http相关的调试信息。

第四:总得来说, nginx 记录日志信息分两个级别,第一个级别的取值为如下之一:

“stderr”, “emerg”, “alert”, “crit”, “error”,”warn”, “notice”, “info”, “debug”

这些值是互斥的,也就是说只能取其中之一,如果在配置文件里加了像如下这种两条配置项:

error_log logs/error.log notice;

error_log logs/error.log info;

那么启动nginx将报错如下:

lenky@lenky-desktop:/usr/local ginx/sbin$ sudo . ginx

src/core gx_conf_file.c 1163 : 1000000

2009/11/18 21:44:46 [emerg] 7027#0: duplicate log level “info” in /usr/local ginx/conf ginx.conf:14

即:日志级别配置重复。

如果我们指定第一个级别为”debug”,那么nginx还允许我们指定第二级别:

“debug_core”, “debug_alloc”, “debug_mutex”, “debug_event”,

“debug_http”, “debug_mail”, “debug_mysql”

第二级别的指定是多选的,因此可以有多条关于第二级别的配置项目:

error_log logs/error.log debug_http;

error_log logs/error.log debug_core;

注意:在且仅在第一个级别为”debug”时才可以有第二级别的配置,其它第一级别情况下指定第二级别将无法启动nginx,比如在这种:

error_log logs/error.log notice;

error_log logs/error.log debug_http;

配置下,启动nginx将获得如下错误信息:

lenky@lenky-desktop:/usr/local ginx/sbin$ sudo . ginx

src/core gx_conf_file.c 1163 : 1000000

2009/11/18 21:50:33 [emerg] 7145#0: invalid log level “debug_http” in /usr/local ginx/conf ginx.conf:10

lenky@lenky-desktop:/usr/local ginx/sbin$

stderr 无法配置,

ngx_set_error_log_levels的第一个for循环是从1开始的,bug?在后面的nginx版本不知道更新没有。

所以emerg是级别最低的?即只有在发送错误时才记录日志?待查 转载请保留地址: http://lenky.info/archives/2011/09/67 或 http://lenky.info/?p=67

已使用 Microsoft OneNote 2016 创建。