1. Directives

1.1. TCP Connections

1.1.1. worker_connections

  • Directive

    1. Syntax: worker_connection number ;
    2. Default: worker_connection 512 ;
    3. Context: events
  • Instroduction

Sets the maximum number of connection that can be open by a worker process.It contain connetions with client,proxied server,and others.Total connections can’t exceed the current process limit on maximum nunber of open files(worker_rlimit_nofile) and current user limit on maximum open files(ulimit -n).

1.1.2. tcp_nopush

  • Directive

    1. Syntax: tcp_nopush on|off ;
    2. Default: tcp_nopush off ;
    3. Context: http,server,location
  • Instroduction

用于解决大量小数据包的场景,将多个数据包合并成一个较大的数据包来进程发送,响应会有延迟,如今的静态资源服务器一般不需要开启。此选项必须要在 sendfile on 时生效。当作为文件服务器时,可以考虑将多个数据包合并成一个大的数据包发送出去,因为这种情况下,响应可以不需要那么的及时。

1.1.3. tcp_nodelay

  • Directive

    1. Syntax: tcp_nodelay on|off ;
    2. Default: tcp_nodelay on ;
    3. Context: http,server,location
  • Instroduction

用于保证网络传输大的实时性,尽可能快的将响应信息发送给客户端,此选项必须要在keepalive开启时生效。

1.2. Keepalive

1.2.1. keepalive_timeout

  • Directive

    1. Syntax: keepalive_timeout timeout [header_timeout] ;
    2. Default: keepalive_timeout 75s ;
    3. Context: http,server,location
  • Instroduction

The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ.
The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.

1.2.2. keepalive_requests

  • Directive

    1. Syntax: keepalive_requests number ;
    2. Default: keepalive_requests 100 ;
    3. Context: http,server,location
  • Instroduction

Sets the maximum number of requests that can be served through one keep-alive connection. After the maximum number of requests are made, the connection is closed.

1.3. Request

1.3.1. client_header_buffer_size

  • Directive

    1. Syntax: client_header_buffer_size size ;
    2. Default: client_header_buffer_size 1k ;
    3. Context: http,server
  • Instroduction

In the most case,set 1k to save client request header is enough.If header has long cookies or from WAP client,1k may be not enough.If a request line or a request header field does not fit into this buffer then larger buffers, configured by the large_client_header_buffers directive, are allocated.

1.3.2. large_client_header_buffers

  • Directive

    1. Syntax: large_client_header_buffers number size ;
    2. Default: large_client_header_buffers 4 8k ;
    3. Context: http,server
  • Instroduction

Sets the maximum number and size of buffers used for reading large client request header. A request line cannot exceed the size of one buffer, or the 414 (Request-URI Too Large) error is returned to the client. A request header field cannot exceed the size of one buffer as well, or the 400 (Bad Request) error is returned to the client.

1.3.3. client_header_timeout

  • Directive

    1. Syntax: client_header_timeout time ;
    2. Default: client_header_timeout 60s ;
    3. Context: http,server
  • Instroduction

Defines a timeout for reading client request header. If a client does not transmit the entire header within this time, the request is terminated with the 408 (Request Time-out) error.

1.3.4. client_body_buffer_size

  • Directive

    1. Syntax: client_body_buffer_size size ;
    2. Default: client_body_buffer_size 8k|16k ;
    3. Context: http,server,location
  • Instroduction

Sets buffer size for reading client request body. In case the request body is larger than the buffer, the whole body or only its part is written to a temporary file. By default, buffer size is equal to two memory pages. In upload server,the client_body_buffer_size may be very large.

.1.3.5 client_body_temp_path

  • Directive

    1. Syntax: client_body_temp_path path [level1 [level2 [level3]]] ;
    2. Default: client_body_temp_path client_body_temp ;
    3. Context: http,server,location
  • Instroduction

Defines a directory for storing temporary files holding client request bodies. Up to three-level subdirectory hierarchy can be used under the specified directory.
If set temporary file: client_body_temp_path /opt/nginx/temporary/client_temp 1 2 ; ,the file may be like: /opt/nginx/temporary/client_temp/8/90/2342929002908

1.3.6. client_max_body_size

  • Directive

    1. Syntax: client_max_body_size size ;
    2. Default: client_max_body_size 1m ;
    3. Context: http,server,location
  • Instroduction

Sets the maximun allowed size of the client body request,specified in request header “Content-Length” filed.If the size exceeds the value,server return 413(request entity too large).In upload server,the value may be set very large.

1.3.7. client_body_timeout

  • Directive

    1. Syntax: client_body_timeout time ;
    2. Default: client_body_timeout 60s ;
    3. Context: http,server,location
  • Instroduction

Defines timeout of between two successive read operations in reqest body,not for the whole request body.If timeout,the server return 408(reques time-out).

1.3.8. resolver

  • Directive

    1. Syntax: resolver address ... [valid=time] [ipv6=on|off] ;
    2. Default: Close
    3. Context: http,server,location
  • Instroduction

Set name servers for resovle upstream proxied domian name to IP address.Name servers are requried in a round-robin fashion.
Name servers can specified by IP address,domain name,or with port(default prot is 53).Before version 1.1.7,only a single name server could be configured.
Specifying name servers using IPv6 addresses is supported starting from versions 1.3.1 and 1.2.2.
By default, nginx will look up both IPv4 and IPv6 addresses while resolving. If looking up of IPv6 addresses is not desired, the ipv6=off parameter can be specified.Resolving of names into IPv6 addresses is supported starting from version 1.5.8.
By default, nginx caches answers using the TTL value of a response. An optional valid parameter allows overriding it.

1.3.9. resolver_timeout

  • Directive

    1. Syntax: resolver_timeout time ;
    2. Default: resolver_timeout 30s ;
    3. Context: http,server,location
  • Instroduction

Sets a timeout for name resolution.

1.4. Response

1.4.1. send_timeout

  • Directive

    1. Syntax: send_timeout time ;
    2. Default: send_timeout 60s ;
    3. Context: http,server,location
  • Instroduction

Sets a timeout for transmitting a response to the client. The timeout is set only between two successive write operations, not for the transmission of the whole response. If the client does not receive anything within this time, the connection is closed.

1.4.2. limit_rate

  • Directive

    1. Syntax: limit_rate rate ;
    2. Default: limit_rate 0 ;
    3. Context: http,server,location,if in location
  • Instroduction

Limits the rate of response transmission to a client. The rate is specified in bytes per second. The zero value disables rate limiting.The limit is set per a request, and so if a client simultaneously opens two connections, the overall rate will be twice as much as the specified limit.
Rate limit can also be set in the $limitrate variable.
Rate limit can also be set in the “X-Accel-Limit-Rate” header field of a proxied server response. This capability can be disabled using the _proxy_ignore_headers
, fastcgi_ignore_headers,uwsgi_ignore_headers, and_ scgi_ignore_headers _directives.

1.4.3. limit_rate_after

  • Directive

    1. Syntax: limit_rate_after size ;
    2. Default: limit_rate_after 0 ;
    3. Context: http,server,location,if in location
  • Instroduction

Sets the initial amount after which the further transmission of a response to a client will be rate limited.