PHP programmers must know to turn on access logs and turn on error logs

Source: Internet
Author: User
Tags apache log

Objective

Originally prepared to explain the Nginx and Apache logs, but the individual is not recommended Apache (purely personal hobby), here does not introduce the Apache log.

As a programmer, the code is more important than a little bit of the log analysis and query. Common logging and setting methods are listed below.

Configuration file

Nginx Sub-access_log and error_log two kinds of logs

Settings need to be in nginx.conf, the default through the source package compiler installation Nginx directory should be

/usr/local/nginx

Directory, if you install through Yum or other means, unclear or unknown nginx specific installation directory, you can use

Find/-name nginx.conf

Or

Nginx-v | grep prefix-------------nginx version:nginx/1.13.9built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) built with OpenSSL 1.0.2k-fips  Jan 2017TLS SNI support enabledconfigure arguments:--prefix=/usr/local/nginx--with-http_ssl_ Module

Open Access Log

If your source package is installed by default, open the path as follows

Vim/usr/local/nginx/nginx.conf

Find the following:

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;        ...}

Open the Log_format to access_log comment, Log_format can define the log specifications for Nginx.

Log_format Default specification Parameter table

name Annotations
$remote _addr IP address of client/user
$time _local Access time
$request Request method + Request Address
$status Request status code consistent with HTTP status code
$body _bytes_sent The requested address size is calculated in bytes format
$http _referer The source of the request, from where it was accessed
$http _user_agent User information (browser information)
$http _x_forwarded_for Forwarding IP Address

Turn on the error log

If your source package is installed by default, open the path as follows

Vim/usr/local/nginx/nginx.conf

Find the following:

Error_log  Logs/error.log, #error_log  logs/error.log  notice; #error_log  logs/error.log  info;

Delete the annotations so that you can store the different error types separately, such as

Error_log Logs/error.log Notice;

Notice are both error types and not write all.

Thanks

Thank you for seeing this, log operations and analysis of related articles I will write some, hope can help you. Thank you

Code changeable, beginner's mind unchanged

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.