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

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

  1. Nginx - Additional Modules, About Your Visitors

    The following set of modules provides extra functionality that will help you find out more informati ...

  2. Nginx - Additional Modules, Limits and Restrictions

    The following modules allow you to regulate access to the documents of your websites — require users ...

  3. Nginx - Additional Modules, Content and Encoding

    The following set of modules provides functionalities having an effect on the contents served to the ...

  4. Nginx - Additional Modules, SSL and Security

    Nginx provides secure HTTP functionalities through the SSL module but also offers an extra module ca ...

  5. 通过Nginx,Tomcat访问日志(access log)记录请求耗时

    一.Nginx通过$upstream_response_time $request_time统计请求和后台服务响应时间 nginx.conf使用配置方式: log_format main '$remo ...

  6. Thinkphp框架网站 nginx环境 访问页面access denied

    今日不熟一个tiinkphp框架网站的时候,由于服务器环境是centos6.5+nginx1.8,已经运行php商城项目很正常, 本以为一切比较简单,直接新建了项目文件夹,xftp上传了程序,并配置n ...

  7. linux+nginx+phpfpm 访问出现Access denied错误解决方案

    linux上安装nginx,php-fpm后访问页面一直出现Access denied错误. 网上搜原因大概如下图: 我试了第一个方案,然后就好了.

  8. Table of Contents - Nginx

    Downloading and  Installing Nginx Nginx for Windows Basic Nginx Configuration Configuration File Syn ...

  9. nginx---reference

    nginx (pronounced "engine x") is a free open source web server written by Igor Sysoev, a R ...

随机推荐

  1. sql server2008添加登录账户配置权限 && 登录时18456错误

    1.如何为SQL Server2008添加登录账户并配置权限 2.SQLSERVER2008 18456错误 http://blog.csdn.net/goodshot/article/details ...

  2. sql2008“备份集中的数据库备份与现有数据库不同”解决方法

    因为是在另一台电脑对同名数据库做的备份,用常规方法还原,提示不是相同数据库,不让还原,在网上找到下面的方法解决了: 一.右击系统数据库master,新建查询 执行以下SQL代码: RESTORE DA ...

  3. Linux单词表

     su:Swith user  切换用户,切换到root用户cat: Concatenate  串联uname: Unix name  系统名称df: Disk free  空余硬盘du: Disk  ...

  4. The Trip PC/UVa IDs: 110103/10137, Popularity: B, Success rate: average Level: 1

    #include<cstdio> #include<iostream> #include<string> #include<algorithm> #in ...

  5. 【转】单例模式(python/c++)

    1. 什么是单例模式(Singleton pattern)? 单例模式是一种常用的软件设计模式.在它的核心结构中只包含一个被称为单例类的特殊类.通过单例模式可以保证系统中一个类只有一个实例而且该实例易 ...

  6. cdoj 1256 昊昊爱运动 预处理/前缀和

    昊昊爱运动 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/show/1256 Descr ...

  7. Android短信彩信收发流程(应用层)

    下图为ComposeMessageActivity中confirmSendMessageIfNeeded部分的信息发送流程.主要以接收者有效性的确认为主,然后转向sendMessage方法进行发送. ...

  8. Apache Solr采用Java开发、基于Lucene的全文搜索服务器

    http://docs.spring.io/spring-data/solr/ 首先介绍一下solr: Apache Solr (读音: SOLer) 是一个开源.高性能.采用Java开发.基于Luc ...

  9. HTTP协议报文、工作原理及Java中的HTTP通信技术详解

    一.web及网络基础       1.HTTP的历史            1.1.HTTP的概念:                 HTTP(Hyper Text Transfer Protocol ...

  10. 使用maven命令建立java项目

    在terminal中输入: mvn archetype:generate -DgroupId={project-packaging} -DartifactId={project-name} -Darc ...