Nginx - Additional Modules, Website Access and Logging

The following set of modules allows you to configure how visitors access your website and the way your server logs requests.

Index

The Index module provides a simple directive named index, which lets you define the page that Nginx will serve by default if no filename is specified in the client request (in other words, it defines the website index page). You may specify multiple filenames; the first file to be found will be served. If none of the specified files are found, Nginx will either attempt to generate an automatic index of the files, if the autoindex directive is enabled, or return a 403 Forbidden error page.

Optionally, you may insert an absolute filename (such as /page.html) but only as the last argument of the directive.

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 is valid in the following contexts: http, server, location.

Autoindex

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

Three columns of information appear for each file—the filename, the file 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 that 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 is set to off, so the date and time of files in the listing appears as GMT time. Set it to on 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 be 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 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 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 to disable access logging at the current level
  • 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)
  • You may use variables in the file path

log_format

Context: http, server, location

Defines a template to be utilized by the access_log directive, describing the contents that should be 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. Please 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 are similar to the open_file_cache and other related directives; the difference being that this applies to access log files only.



The Log module also enables several new variables, though they are 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
时间: 2024-08-06 08:28:36

Nginx - Additional Modules, Website Access and Logging的相关文章

Nginx - Additional Modules, Content and Encoding

The following set of modules provides functionalities having an effect on the contents served to the client, either by modifying the way the response is encoded, by affecting the headers, or by generating a response from scratch. Empty GIF The purpos

Nginx - Additional Modules, About Your Visitors

The following set of modules provides extra functionality that will help you find out more information about the visitors, such as by parsing client request headers for browser name and version, assigning an identifier to requests presenting similari

Nginx - Additional Modules, Limits and Restrictions

The following modules allow you to regulate access to the documents of your websites — require users to authenticate, match a set of rules, or simply restrict access to certain visitors. Auth_basic Module The auth_basic module enables the basic authe

nginx 编译某个模板的问题./configure: error: SSL modules require the OpenSSL library. You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library stati

[email protected]:/usr/local/src/nginx-1.9.8# ./configure --prefix=/usr/local/nginx  --add-module=/usr/local/src/nginx-rtmp-module  --with-htchecking for OS + Linux 4.4.0-116-generic x86_64checking for C compiler ... found + using GNU C compiler + gc

logstash grok 分析 nginx access 日志

为了便于量化分析nginx access日志,使用logstash 进行筛选匹配 1.确定nginx 日志格式     log_format access '$remote_addr - $remote_user [$time_local] '               '$http_host $request_method $uri '               '$status $body_bytes_sent '               '$upstream_status $ups

Permanent Link: 101 ways to speed up your Magento e-commerce website

101 ways to speed up your Magento e-commerce website May 18, 2010/in E-commerce, Magento /by Guido Jansen As you probably know by now, Google is Using site speed in web search ranking. And I couldn’t agree more: speed is important for your site, and

nginx各版本变化说明

from: http://nginx.org/en/CHANGES 使用nginx cache,想要配置cache数据自动清理时间,发现一个参数 clean_time ,但发现很早这个参数就从稳定版本中 清除了.目前来看,只能用purge指令控制. 以下是 nginx 各个版本的 changes 说明. Changes with nginx 1.7.7 28 Oct 2014 *) Change: now nginx takes into account the "Vary" head

NGINX实现反向代理

一.安装NGINX 略,请自行百度,GOOGEL 二.配置文件1.由上面的步骤,我们看到配置文件放置在/etc/nginx/目录下:主要配置文件:/etc/nginx/nginx.conf 扩展配置文件:/etc/nginx/conf.d/*.conf user www-data; worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 768; # multi_accept on; } http { ##

搭建LVS+Keepalived+nginx+tomcat高可用性,高性能jsp集群

LVS-master:192.168.0.210 LVS-backup:192.168.0.211 LVS-VIP:192.168.0.209 nginx+tomcat:192.168.0.212 nginx+tomcat:192.168.0.227 安装nginx所需包: Nginx-1.6.0.tar.gz和pcre-8.35.zip 一.安装pcre-8.35 1 #unzip pcre-8.35.zip 2 #cd pcre-8.35 3 #./configure 4 #make 5 #