在 Debian 下,Nginx 的日志级别是通过 nginx 配置文件 来设置的,不是系统服务参数。
Nginx 的 error_log 支持以下级别(从低到高):
debug
info
notice
warn
error
crit
alert
emerg
默认级别一般是:error
级别越低,日志越详细;
debug最详细,但性能影响较大。
编辑 Nginx 主配置:
sudo nano /etc/nginx/nginx.conf
在 events 或 http 块中设置:
error_log /var/log/nginx/error.log warn;
示例(http 块内全局生效):
http {
error_log /var/log/nginx/error.log warn;
...
}
编辑站点配置(如 /etc/nginx/sites-enabled/default):
server {
error_log /var/log/nginx/example-error.log debug;
...
}
access_log 没有日志级别概念,只有是否记录:
access_log off;
或:
access_log /var/log/nginx/access.log;
如果你想用 debug 级别:
debug检查是否支持:
nginx -V 2>&1 | grep debug
如果 没有 --with-debug,Debian 默认包通常 不支持 debug 日志。
sudo apt install nginx-extras
或源码编译时加:
--with-debug
sudo nginx -t
sudo systemctl reload nginx
# 全局
error_log /var/log/nginx/error.log error;
# 某 server
server {
error_log /var/log/nginx/site.log info;
}
如果你愿意,可以告诉我:
我可以给你更精确的建议。