nginx错误日志
nginx错误日志
nginx能够将自身运行故障的信息也写入到指定的日志文件中。对于错误信息的调试,是维护ginx的重要手段,
指令是error_log,可以放在http{}全局中,也可以单独为虚拟主机记录
语法:
error_log file level;
日志级别在乎debug|info|notice|warn|error|crit|alert|emerg
级别越高,日志记录越少,生产常用模式是warn|error|crit级别
日志的记录,会给服务器增加额外大量的IO消耗,按需修改
nginx.conf中修改如下,针对虚拟主机添加错误日志
[root@backup nginx_yy]# vim /opt/tngx232/conf/extra/nginx_yy.conf
server {
listen 80;
server_name www.nginx_yy.com;
charset utf-8;
error_log logs/nginx_yy.error.log; #开启错误日志功能,定义错误日志路径,名称
access_log logs/yy_access.log;
location / {
root /www/nginx_yy;
#index index.html index.htm;
autoindex on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
修改完成后,检查nginx语法,重启nginx
[root@backup nginx_yy]# nginx -t
nginx: the configuration file /opt/tngx232/conf/nginx.conf syntax is ok
nginx: configuration file /opt/tngx232/conf/nginx.conf test is successful
[root@backup nginx_yy]# nginx -s reload
查看错误日志路径
[root@backup nginx_yy]# ll /opt/tngx232/logs/
total 27276
drwxr-xr-x 4 root root 26 Aug 2 00:00 2020
-rw-r--r-- 1 root root 18800000 Aug 2 01:26 access.log
-rw-r--r-- 1 root root 9101850 Aug 1 11:10 access.log_2020-07-31
-rw-r--r-- 1 root root 180 Aug 2 00:27 cc_access.log
-rw-r--r-- 1 root root 10320 Aug 2 02:08 error.log
-rw-r--r-- 1 root root 5 Aug 1 22:58 nginx.pid
-rw-r--r-- 1 root root 0 Aug 2 02:08 nginx_yy.error.log
-rw-r--r-- 1 root root 1912 Aug 2 00:55 yy_access.log
监控错误日志文件,用浏览器访问nginx