Nginx-additional Modules, Website Access and Logging

Source: Internet
Author: User
Tags local time

The following set of modules allows you to configure how visitors access your website and the "the" the "Your Server logs request" S.

Index

The index module provides a simple directive named Index, which lets your define the page that Nginx would serv E By default if no filename was specified in the client request (on other words, it defines the website index page). specify multiple filenames; the first file to be found'll be served. If none of the specified files is found, Nginx would either attempt to generate an automatic index of the files, if the autoindex directive is enabled, or return a 403 Forbidden error page.

Optionally, may insert a absolute filename (such as /page.html) but only as the last argument of the Directi Ve.

Syntax: index file1 [file2 ...] [Absolute_file];

Default value: index.html

eaxmple:

Index index.php index.html index.htm;
Index index.php index2.php/catchall.php;

This directive was valid in the following contexts: http, server, location.

AutoIndex

If Nginx cannot provide an index page for the requested directory, the default behavior are to return a 403 forbidden HTTP error page. With the following set of directives, you enable a automatic listing of the files that is present in the requested Direc Tory

Three columns of information appear for each file-the filename, the file is date and time, and the file size in bytes.

AutoIndex

Context: http, server, location

Enables or disables automatic directory listing for directories missing an index page.

Syntax: on or off

Autoindex_exact_size

Context: http, server, location

If set to on, this directive ensures, the listing displays file sizes in bytes. Otherwise, another unit is employed, such as KB, MB, or GB.

Syntax: on or off

Default value: on

Autoindex_localtime

Context: http, server, location

By default, this directive are set to offwith the date and time of the files in the listing appears as GMT time. Set it- to-make use of the local server time.

Syntax: on or off

Default value: off

Random Index

This module enables a simple directive, Random_index, which can is used within a location block in order For Nginx to return an index page selected randomly among the files of the specified directory.

This module is not a included in the default Nginx build.

Syntax: on or off

Log

This module controls the behavior of Nginx regarding access logs. It is a key module for system administrators as it allows analyzing the runtime behavior of the Web applications. It is composed of three essential directives:

Access_log

Context: http, server, location

This parameter defines the access log file path, the format of entries in the Access log by selecting a template Name, or disables access logging.

Syntax: access_log path [format [buffer=size]] | off;

Some remarks concerning the directive syntax:

    • Use access_log off -disable access logging at the
    • The format argument corresponds to a template declared with the log_format directive, described below
    • If The format argument is not specified, the default format is employed (combined)
    • Variables in the file path
Log_format

Context: http, server, location

Defines a template to being utilized by the access_log directive, describing the contents that should is included in An entry of
The Access log.

Syntax: log_format template_name format_string;

The default template is called combined and matches the following example:

Log_format combined ' $remote _addr-$remote _user [$time _local] ' "$request" $status $body _bytes_sent ' "$http _referer" "$ Http_user_agent "';

# Other Example
Log_format simple ' $remote _addr $request ';

Open_log_file_cache

Context: http, server, location

Configures the cache for log file descriptors. Refer to the open_file_cache directive of the HTTP Core Module for additional information.

Syntax: open_log_file_cache max=n [Inactive=time] [min_uses=n] [valid=time] | off;

The arguments is similar to the Open_file_cache and other related directives; The difference being that this applies to access log files is only.

The Log module also enables several new variables, though they is only accessible when writing Log entries:

  • $connection: The connection number
  • $pipe: The variable is set to "P" if the request was pipelined
  • $time _local: local time (at the time of writing the log entry)
  • $msec: Local time (at the time of writing the log entry) to the microsecond
  • $request _time: Total length of the request processing, in milliseconds
  • $status: Response Status Code
  • $bytes _sent: Total number of bytes sent to the client
  • $body _bytes_sent: Number of bytes sent to the client for the response body
  • $apache _bytes_sent: Similar to $body _bytes, which corresponds to the%B parameter of Apache ' s Mod_log_config
  • $request _length: Length of the request body

Nginx-additional Modules, Website Access and Logging

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.