通常情况下,Nginx 的错误日志级别是 error,对于Nginx 用户来说,将日志设置为info级别就足够用了。对于比较复杂的情况,需要看到更详细的 debug 级别的日志,如果只是把error_log级别设置为debug,Nginx 记录下来的还是info级别以上的信息。只有激活 Nginx的 debug日志才能得到 debug级别的日志信息。下面记录添加debug错误日志的过程。
#查看当前编译选项
[root@username sbin]# ./nginx -V
nginx version: nginx/1.10.3
built by gcc 4.8.2 20140120 (Red Hat 4.8.2-16) (GCC)
configure arguments: --prefix=/deploy/nginx
#上传Nginx原生文件
scp /Users/username/Downloads/nginx-1.12.0.tar.gz dfecmes/dfecmes@192.168.1.133:/software
#解压
tar -xzvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
#设置编译选项
./configure --prefix=/software/nginx-debug --with-debug
执行以上命令时出现如下错误:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
解决办法,安装pcre-devel:
yum -y install pcre-devel
结果如下:
[root@test1 software]# yum -y install pcre-devel
已加载插件:fastestmirror, langpacks
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/2): extras/7/x86_64/primary_db | 167 kB 00:00:00
(2/2): updates/7/x86_64/primary_db | 5.6 MB 00:00:02
Loading mirror speeds from cached hostfile
* base: mirrors.btte.net
* extras: mirrors.neusoft.edu.cn
* updates: mirrors.neusoft.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 pcre-devel.x86_64.0.8.32-15.el7_2.1 将被安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================================================================================================================
正在安装:
pcre-devel x86_64 8.32-15.el7_2.1 base 479 k
事务概要
===================================================================================================================================================================================================================
安装 1 软件包
总下载量:479 k
安装大小:1.4 M
Downloading packages:
pcre-devel-8.32-15.el7_2.1.x86_64.rpm | 479 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : pcre-devel-8.32-15.el7_2.1.x86_64 1/1
验证中 : pcre-devel-8.32-15.el7_2.1.x86_64 1/1
已安装:
pcre-devel.x86_64 0:8.32-15.el7_2.1
完毕!
#编译源代码并安装
make
make install
然后可以通过 error_log 指令设置 debug 级别:
error_log /path/to/log debug;