Home > Article > Backend Development > What PHP programmers must know about enabling access logs and enabling error logs
I originally planned to explain the logs of nginx and apache, but I personally don’t recommend apache (it’s purely a personal hobby), so I won’t introduce the logs of apache here. .
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 types of logs: access_log and error_log
The settings need to be in nginx.conf. By default, the nginx directory should be compiled and installed through the source code package in
/usr/local/nginx
directory, if you install it through yum or other methods, and you don’t know or don’t know the specific installation directory of nginx, 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; ... }
Just open the comments from log_format to 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 | The request source, where it is accessed from |
$http_user_agent | User information (browser information) |
$http_x_forwarded_for | Forwarded 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 the error type. If you don't write it, it will be all.
Thank you for reading this. I will write some more articles about log operation and analysis later, I hope they can help you. Thank you
The code changes, but the original intention remains the same
Related articles:
php-cgi.exe Turn on the error log
Teach you how to enable PHP's error_log
Related videos:
PHP development practical tutorial on making a simple calendar
The above is the detailed content of What PHP programmers must know about enabling access logs and enabling error logs. For more information, please follow other related articles on the PHP Chinese website!