Error log configuration and access log configuration and log records

Source: Internet
Author: User
Tags syslog
Error log configuration and access log configuration
[Root@slave nginx]# vi/etc/nginx/nginx.conf
Worker_processes 1;
Error_log/var/log/nginx/error.log;
Events {
Worker_connections 1024;
}
HTTP {
Include Mime.types;
Default_type Application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Log_format comman ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
"$http _user_agent" "$request _body" "$request _time";
server {
Listen 80;
server_name www.wolf.com wolf.com;
Location/{
Root html/www;
Index index.html index.htm;
}
Access_log/var/log/nginx/www.log Comman;
}
server {
Listen 80;
server_name bbs.wolf.com;
Location/{
Root Html/bbs;
Index index.html index.htm;
}
}
server {
Listen 80;
server_name blog.wolf.com;
Location/{
Root Html/blog;
Index index.html index.htm;
}
}
# #status
server {
Listen 80;
server_name status.wolf.com;
Location/{
Stub_status on;
Access_log off;
}
}
}
The configuration is complete and the test is as follows
[Root@slave nginx]# Curl www.wolf.com
Http://www.wolf.com
[Root@slave nginx]# tail-f Www.log
192.168.0.203--[11/jun/2016:16:26:52 +0800] "get/http/1.1"-"" curl/7.19.7 (X86_64-REDHAT-LINUX-GNU) libcurl/ 7.19.7 nss/3.14.0.0 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 ""-"" 0.000 "

Accessing Tests through a browser

============================================================

Logs are very advantageous for statistical troubleshooting.
This article summarizes the Nginx log-related configuration such as Access_log, Log_format, Open_log_file_cache
, Log_not_found, Log_subrequest, Rewrite_log, Error_log.
Nginx has a very flexible logging mode. Each level of configuration can have its own independent access logs.
The log format is defined by the Log_format command.
The ngx_http_log_module is used to define the request log format.
1. Access_log Instructions
Syntax: access_log path [format [Buffer=size [Flush=time]];
Access_log path Format gzip[=level] [buffer=size] [flush=time];
Access_log Syslog:server=address[,parameter=value] [format];
Access_log off;
Default value: Access_log logs/access.log combined;
Configuration segment: HTTP, server, location, if in location, limit_except
gzip compression level.
Buffer sets the memory buffer size.
The maximum amount of time that flush is saved in the cache.
Log not logged: Access_log off;
Logging using the default combined format: Access_log logs/access.log or Access_log logs/access.log combined;
2. log_format directive
Syntax: Log_format name string ...;
Default value: Log_format combined "...";
Configuration segment: http
Name represents the format name, and string represents the format of the literal.
Log_format has a default combined log format that does not have to be set, equivalent to the Apache combined log format, as follows:
Log_format combined ' $remote _addr-$remote _user [$time _local] '
"$request" $status $body _bytes_sent '
' "$http _referer" "$http _user_agent";
If the nginx is in the load balancer, after squid,nginx the reverse proxy, the Web server cannot obtain the real IP address of the client directly.
$remote _addr Gets the IP address of the reverse proxy. The reverse proxy server can add x-forwarded-for information to the HTTP header of the forwarding request,
The server address used to record client IP addresses and client requests.
PS: Get the user real IP see http://www.ttlsa.com/html/2235.html below:
Log_format porxy ' $http _x_forwarded_for-$remote _user [$time _local] '
"$request" $status $body _bytes_sent '
' "$http _referer" "$http _user_agent";
The log format allows for the inclusion of variable annotations as follows:
$remote _addr, $http _x_forwarded_for log client IP address
$remote _user record the client user name
$request record the URL and HTTP protocol for the request
$status Record Request Status
$body _bytes_sent the number of bytes sent to the client, excluding the size of the response header, which is compatible with the "%B" parameter in the Apache module MOD_LOG_CONFIG.
The total number of bytes $bytes _sent sent to the client.
$connection the serial number of the connection.
$connection _requests The number of requests currently obtained through a connection.
$msec Log write time. The unit is seconds, and the precision is milliseconds.
$pipe if the request is sent over an HTTP pipelining (pipelined), the pipe value is "P", otherwise ".".
$http _referer record from which page the link was accessed.
$http _user_agent Record client browser-related information
$request the length of the _length request (including the request line, the request header, and the request body).
$request _time request processing time in seconds, precision milliseconds, starting with the first byte read into the client until the last word is character to the client for log writes.
$time The local time in _iso8601 ISO8601 standard format.
$time The local time in the _local common log format.
[WARNING] The response header sent to the client has a "sent_http_" prefix. Like $sent_http_content_range. [/warning]
Examples are as follows:
HTTP {
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
"$status" $body _bytes_sent "$http _referer"
' "$http _user_agent" "$http _x_forwarded_for" '
' "$gzip _ratio" $request _time $bytes _sent $request _length ';

Log_format srcache_log ' $remote _addr-$remote _user [$time _local] "$request" '
"$status" $body _bytes_sent $request _time $bytes _sent $request _length '
' [$upstream _response_time] [$srcache _fetch_status] [$srcache _store_status] [$srcache _expire] ';

Open_log_file_cache max=1000 inactive=60s;

server {
Server_Name ~^ (www\.)? (.+)$;
Access_log Logs/$2-access.log Main;
Error_log Logs/$2-error.log;

Location/srcache {
Access_log Logs/access-srcache.log Srcache_log;
}
}
}

3. Open_log_file_cache Instructions
Syntax: Open_log_file_cache max=n [Inactive=time] [min_uses=n] [valid=time];
Open_log_file_cache off;
Default value: Open_log_file_cache off;
Configuration segment: HTTP, server, location
For each log record, the file is opened, written to the log, and then closed. You can use Open_log_file_cache to set the log file cache (which is off by default) in the following format:
The parameter comments are as follows:
Max: Sets the maximum number of file descriptors in the cache, and uses the LRU algorithm to close the descriptor if the cache is full.
Inactive: Set survival time, default is 10s
Min_uses: Set the log file descriptor into the cache after the minimum number of times it is used in the inactive time period, 1 times by default
Valid: Set check frequency, default 60s
Off: Disable caching
Examples are as follows:
Open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
4. Log_not_found Instructions
Syntax: Log_not_found on | Off
Default value: Log_not_found on;
Configuration segment: HTTP, server, location
Whether a non-existent error is logged in the Error_log. The default is.
5. Log_subrequest Instructions
Syntax: Log_subrequest on | Off
Default value: Log_subrequest off;
Configuration segment: HTTP, server, location
Whether to record the access log for the child request in the Access_log. Default is not logged.
6. Rewrite_log Instructions
Provided by the Ngx_http_rewrite_module module. Used to record the rewrite log. For debug rewrite rules, it is recommended to open. Nginx Rewrite rules guide
Syntax: Rewrite_log on | Off
Default value: Rewrite_log off;
Configuration segment: HTTP, server, location, if
When enabled, an notice level rewrite log is logged in error log.
7. Error_log Instructions
Syntax: Error_log file | stderr | Syslog:server=address[,parameter=value] [Debug | info | notice | warn | error | crit | alert | Emerg];
Default value: Error_log logs/error.log error;
Configuration segment: Main, HTTP, server, location
Configure the error log.


This article summarizes the Nginx log-related configuration such as Access_log, Log_format, Open_log_file_cache
, Log_not_found, Log_subrequest, Rewrite_log, Error_log.
Nginx has a very flexible logging mode. Each level of configuration can have its own independent access logs.
The log format is defined by the Log_format command.
The ngx_http_log_module is used to define the request log format.
1. Access_log Instructions
Syntax: access_log path [format [Buffer=size [Flush=time]];
Access_log path Format gzip[=level] [buffer=size] [flush=time];
Access_log Syslog:server=address[,parameter=value] [format];
Access_log off;
Default value: Access_log logs/access.log combined;
Configuration segment: HTTP, server, location, if in location, limit_except
gzip compression level.
Buffer sets the memory buffer size.
The maximum amount of time that flush is saved in the cache.
Log not logged: Access_log off;
Logging using the default combined format: Access_log logs/access.log or Access_log logs/access.log combined;
2. log_format directive
Syntax: Log_format name string ...;
Default value: Log_format combined "...";
Configuration segment: http
Name represents the format name, and string represents the format of the literal.
Log_format has a default combined log format that does not have to be set, equivalent to the Apache combined log format, as follows:
Log_format combined ' $remote _addr-$remote _user [$time _local] '
"$request" $status $body _bytes_sent '
' "$http _referer" "$http _user_agent";
If the nginx is in the load balancer, after squid,nginx the reverse proxy, the Web server cannot obtain the real IP address of the client directly.
$remote _addr Gets the IP address of the reverse proxy. The reverse proxy server can add x-forwarded-for information to the HTTP header of the forwarding request,
The server address used to record client IP addresses and client requests.
PS: Get the user real IP see http://www.ttlsa.com/html/2235.html below:
Log_format porxy ' $http _x_forwarded_for-$remote _user [$time _local] '
"$request" $status $body _bytes_sent '
' "$http _referer" "$http _user_agent";
The log format allows for the inclusion of variable annotations as follows:
$remote _addr, $http _x_forwarded_for log client IP address
$remote _user record the client user name
$request record the URL and HTTP protocol for the request
$status Record Request Status
$body _bytes_sent the number of bytes sent to the client, excluding the size of the response header, which is compatible with the "%B" parameter in the Apache module MOD_LOG_CONFIG.
The total number of bytes $bytes _sent sent to the client.
$connection the serial number of the connection.
$connection _requests The number of requests currently obtained through a connection.
$msec Log write time. The unit is seconds, and the precision is milliseconds.
$pipe if the request is sent over an HTTP pipelining (pipelined), the pipe value is "P", otherwise ".".
$http _referer record from which page the link was accessed.
$http _user_agent Record client browser-related information
$request the length of the _length request (including the request line, the request header, and the request body).
$request _time request processing time in seconds, precision milliseconds, starting with the first byte read into the client until the last word is character to the client for log writes.
$time The local time in _iso8601 ISO8601 standard format.
$time The local time in the _local common log format.
[WARNING] The response header sent to the client has a "sent_http_" prefix. Like $sent_http_content_range. [/warning]
Examples are as follows:
HTTP {
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
"$status" $body _bytes_sent "$http _referer"
' "$http _user_agent" "$http _x_forwarded_for" '
' "$gzip _ratio" $request _time $bytes _sent $request _length ';

Log_format srcache_log ' $remote _addr-$remote _user [$time _local] "$request" '
"$status" $body _bytes_sent $request _time $bytes _sent $request _length '
' [$upstream _response_time] [$srcache _fetch_status] [$srcache _store_status] [$srcache _expire] ';

Open_log_file_cache max=1000 inactive=60s;

server {
Server_Name ~^ (www\.)? (.+)$;
Access_log Logs/$2-access.log Main;
Error_log Logs/$2-error.log;

Location/srcache {
Access_log Logs/access-srcache.log Srcache_log;
}
}
}

3. Open_log_file_cache Instructions
Syntax: Open_log_file_cache max=n [Inactive=time] [min_uses=n] [valid=time];
Open_log_file_cache off;
Default value: Open_log_file_cache off;
Configuration segment: HTTP, server, location
For each log record, the file is opened, written to the log, and then closed. You can use Open_log_file_cache to set the log file cache (which is off by default) in the following format:
The parameter comments are as follows:
Max: Sets the maximum number of file descriptors in the cache, and uses the LRU algorithm to close the descriptor if the cache is full.
Inactive: Set survival time, default is 10s
Min_uses: Set the log file descriptor into the cache after the minimum number of times it is used in the inactive time period, 1 times by default
Valid: Set check frequency, default 60s
Off: Disable caching
Examples are as follows:
Open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
4. Log_not_found Instructions
Syntax: Log_not_found on | Off
Default value: Log_not_found on;
Configuration segment: HTTP, server, location
Whether a non-existent error is logged in the Error_log. The default is.
5. Log_subrequest Instructions
Syntax: Log_subrequest on | Off
Default value: Log_subrequest off;
Configuration segment: HTTP, server, location
Whether to record the access log for the child request in the Access_log. Default is not logged.
6. Rewrite_log Instructions
Provided by the Ngx_http_rewrite_module module. Used to record the rewrite log. For debug rewrite rules, it is recommended to open. Nginx Rewrite rules guide
Syntax: Rewrite_log on | Off
Default value: Rewrite_log off;
Configuration segment: HTTP, server, location, if
When enabled, an notice level rewrite log is logged in error log.
7. Error_log Instructions
Syntax: Error_log file | stderr | Syslog:server=address[,parameter=value] [Debug | info | notice | warn | error | crit | alert | Emerg];
Default value: Error_log logs/error.log error;
Configuration segment: Main, HTTP, server, location
Configure the error log.


The above describes the error log configuration and access log configuration as well as log records, including aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.