可参考官方关于nginx的debug的说明,较新. http:///en/docs/debugging_log.html
请关注最新修正合订:http:///ebook/ 这一系列的文章还是在09年写的,存在电脑里很久了,现在贴出来。顺序也不记得了,看到那个就发那个吧,最近都会发上来。欢迎转载,但请保留链接:http:///,谢谢。 第一:打开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/nginx/sbin$ sudo ./nginx src/core/ngx_conf_file.c 1163 : 1000000 2009/11/18 21:44:46 [emerg] 7027#0: duplicate log level “info” in /usr/local/nginx/conf/nginx.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/nginx/sbin$ sudo ./nginx src/core/ngx_conf_file.c 1163 : 1000000 2009/11/18 21:50:33 [emerg] 7145#0: invalid log level “debug_http” in /usr/local/nginx/conf/nginx.conf:10 lenky@lenky-desktop:/usr/local/nginx/sbin$ stderr无法配置, ngx_set_error_log_levels的第一个for循环是从1开始的,bug?在后面的nginx版本不知道更新没有。 所以emerg是级别最低的?即只有在发送错误时才记录日志?待查 转载请保留地址:http:///2011/09/10/%e6%89%93%e5%bc%80nginx%e8%b0%83%e8%af%95/或 http:///?p=67
|