Nginx log Configuration

Source: Internet
Author: User

Log_format is used to set the log record format:

Log_format name format

Name indicates the format name, and format indicates the equivalent format. Log_format has a default combined log format, which is equivalent to apache combined log format, as shown below:

Log_format combined '$ remote_addr-$ remote_user [$ time_local]'

'"$ Request" $ status $ body_bytes_sent'

'"$ Http_referer" "$ http_user_agent "';

If nginx is in the Server Load balancer, squid, and nginx reverse proxy, the web server cannot directly obtain the real IP address of the client. $ Remote_addr: Obtain the IP address of the reverse proxy. The Reverse Proxy Server adds X-Forwarded-For information in the http header of the Forwarded request to record the Client IP address and the server address of the client request. As follows:

Log_format porxy '$ http_x_forwarded_for-$ remote_user [$ time_local]'

'"$ Request" $ status $ body_bytes_sent'

'"$ Http_referer" "$ http_user_agent "';

The parameter annotations are as follows:

$ Remote_addr, $ http_x_forwarded_for record the Client IP Address

$ Remote_user record the client User Name

$ Time_local records the access time

$ Request records the request URL and HTTP protocol

$ Status records the Request status

$ Body_bytes_sent record size of the file sent to the client

$ Http_referer records the access from which page Link

$ Http_user_agent: Record client browser Information

Access_log is used to specify the log file path:

Access_log path [format [buffer = size | off]

Buffer sets the size of the memory cache area.

No logs:

Access_log off;

Use the default combined format to record logs:

Access_log logs/access. log or access_log logs/access. log combined;

Use the custom log format:

Access_log logs/access. log proxy buffer = 32 k;

Each server_name corresponds to one log file:

Access_log logs/$ server_name.log combined;

The log file contains variables. Pay attention to the following issues:

Buffer is not used

For each log record, the file is opened first, then the log is written, and then disabled. You can use open_log_file_cache to set the Log File Cache (off by default). The format is as follows:

Open_log_file_cache max = n [inactive = time] [min_uses = n] [valid = time] | off

The parameter annotations are as follows:

Max: sets the maximum number of file descriptors in the cache. The LRU algorithm is used.

Inactive: Set the survival time. The default value is 10 s.

Min_uses: sets the minimum number of log files used, and the log file descriptor is recorded in the cache. The default value is 1.

Valid: sets the check frequency. The default value is 60 s.

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.