The content of this article is about common Nginx logs and setting methods. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
As a programmer, something a little more important than coding is log analysis and query. Common logs and setting methods are listed below.
nginx is divided into two logs: access_log and error_log
The settings need to be in nginx.conf, and the default is passed The source code package compilation and installation nginx directory should be in the
/usr/local/nginx
directory. If you install it through yum or other methods and do not know or do not know the specific nginx installation directory, you can use
find / -name nginx.conf
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
If your source code package is installed by default, open the path as follows
vim /usr/local/nginx/nginx.conf
Find the following content
http { include mime.types; default_type application/octet-stream; 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; ... }
Change log_format Just open the comment of access_log. Log_format can define the log specifications of nginx.
Name | Annotation |
---|---|
$remote_addr | Client/user IP address |
$time_local | Access time |
$request | Request method Request address |
$status | The request status code is consistent with the HTTP status code |
$body_bytes_sent | The requested address size is calculated in bytes format |
$http_referer | Request source, from what Local access |
$http_user_agent | User information (browser information) |
$http_x_forwarded_for | Forward IP address |
If your source code package is installed by default, open the path as follows
vim /usr/local/nginx/nginx.conf
Find the following content
error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info;
Just delete the annotation. You can store different error types separately. For example,
error_log logs/error.log notice;
notice is an error type. If you don’t write it, it will be all.
Recommended related articles:
Nginx common log splitting methods nginx apache nginx php nginx rewrite
nginx common configurationThe above is the detailed content of Common Nginx logs and configuration methods in PHP. For more information, please follow other related articles on the PHP Chinese website!