nginx开启debug模式

在Nginx配置文件中,error_log和access_log指令的第二个参数是日志格式,不能直接使用debug作为日志格式。

如果想要开启debug级别的日志,可以使用下面的方式,修改nginx.conf配置文件:

## 对于error_log 直接在后面添加debug参数
error_log /var/log/nginx/error.log debug;


## 对于access_log,需要指定一种自定义的日志格式来输出debug级别的日志
log_format debuglog '[$time_local] $remote_addr $request_uri '
                    '$status $request_time $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';

access_log /var/log/nginx/access.log debuglog;

然后重启nginx服务器

systemctl restart nginx.service

注意: access_log是用来记录Nginx服务器上客户端请求的日志指令,一般情况下不需要开启debug模式。access_log的日志级别默认为“info”,可以记录请求的基本信息,如时间、请求方法、请求URL、客户端IP地址等。如果需要更详细的请求日志信息,可以使用Nginx的“ngx_http_log_module”模块提供的其他日志格式。

参考书籍:《深入理解Nginx:模块开发与架构》 2.2.5

猜你喜欢

转载自blog.csdn.net/weixin_43161088/article/details/129405927
今日推荐