<p style="text-align: center">
前言
@H_301_2@本来准备讲解Nginx和apache的日志的,但是个人不太推荐apache(纯属个人爱好),这里就不介绍apache的日志了。 @H_301_2@作为一名程序员,比码代码还重要那么一点点的东西就是日志的分析和查询。下面列出常见日志及设置方法。 @H_301_2@配置文件
@H_301_2@Nginx分access_log和error_log两种日志@H_301_2@设置需要在Nginx.conf中,默认通过源码包编译安装Nginx目录应在
PHP;">
/usr/local/Nginx
@H_301_2@目录下,如果你通过yum或者其他方式安装,不清楚或不知道Nginx具体安装目录,可以使用
Nginx.conf
@H_301_2@or
Nginx -V | grep prefix
-------------
Nginx version: Nginx/1.13.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/Nginx --with-http_ssl_module
@H_301_2@开启访问日志
@H_301_2@如果是你源码包默认安装的,打开路径如下Nginx/Nginx.conf
@H_301_2@找到如下内容
PHP;">
http {
include mime.types;
default_type application/octet-stream;
@H_301_2@将log_format到access_log的注释打开即可,log_format可定义Nginx的日志规格。
@H_301_2@log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log logs/access.log main;
...
}
log_format默认规格参数表
@H_301_2@注解 |
---|
开启错误日志
@H_301_2@如果是你源码包默认安装的,打开路径如下Nginx/Nginx.conf
@H_301_2@找到如下内容