Nginx 教程

主要文档

Nginx功能概述 为什么选择Nginx Nginx安装 常见问题(FAQ) 配置符号参考 调试 nginx 优化 Nginx 运行和控制Nginx

核心模块

Nginx事件模块 Nginx主模块

基本模块

Browser模块 Charset模块 Geo模块 HttpAccess模块 HttpAuthBasic模块 HttpAutoindex模块 HttpEmptyGif模块 HttpFcgi模块 HttpGzip模块 HttpHeaders模块 HttpIndex模块 HttpIndex模块. HttpLimit zone HttpLimitReqest模块 HttpLog模块 HttpProxy模块 HttpRewrite模块 HttpSSI模块 HttpUserId http核心模块 map Memcached

其他模块

Addition模块 EmbeddedPerl flv GooglePerftools HttpDav模块 HttpGeoIP HttpGzipStatic HttpImageFilter HttpRealIp HttpSecureLink HttpSSL HttpSubstitution HttpXSLT RandomIndex StubStatus模块

mail模块

MailAuth MailCore MailProxy MailSSL

安装

nginx php-fpm安装配置 nginx在fedora上的安装 nginx在freebsd上的安装 nginx在ubuntu上的安装 nginx在windows上的安装

配置示例和方法

HWLoadbalancerCheckErrors nginx防盗链 负载均衡 完整例子 完整例子2 虚拟主机

HttpLog模块


ngx_http_log_module 实例

log_format  gzip  '$remote_addr - $remote_user [$time_local]  '
: '"$request" $status $bytes_sent '
: '"$http_referer" "$http_user_agent" "$gzip_ratio"';
access_log  /spool/logs/nginx-access.log  gzip  buffer=32k; 

指令

  • access_log
  • log_format

access_log

语法:*access_log path [format [buffer=size | off ] 默认值:access_log log/access.log combined*

作用域:*http, server, location*

指令 access_log 指派路径、格式和缓存大小。参数 "off" 将清除当前级别的所有 access_log 指令。如果未指定格式,则使用预置的 "combined" 格式。缓存不能大于能写入磁盘的文件的最大大小。在 FreeBSD 3.0-6.0 ,缓存大小无此限制。

log_format

语法:*log_format name format [format ...]*

默认值:*log_format combined "..."*

作用域:*http*server

Directive log_format describes the format of a log entry. Besides general variables in the format it is possible to use variables which exist only at the moment of record into the log:

  • $body_bytes_sent, the number of bytes, transmitted to client minus the response headers, variable is compatible with parameter %B of module Apache's mod_log_config (this was called $apache_bytes_sent, before version 0.3.10)
  • $bytes_sent, the number of bytes, transmitted to client
  • $connection, the number of connection
  • $msec, the time with an accuracy to microseconds at the moment of the log entry
  • $pipe, "p" if request was pipelining
  • $request_length, the length of the body of the request
  • $request_time, the time of working on request in seconds
  • $status, status of answer
  • $time_local, local time into common log format.

The headers, transmitted to client, begin from the prefix "senthttp", for example, $sent_http_content_range.

In the configuration there is always a predetermined format "combined":

log_format  combined  '$remote_addr - $remote_user [$time_local]  '
: '"$request" $status $apache_bytes_sent '
: '"$http_referer" "$http_user_agent"'; 

参考

原始文档