Nginx 基本指令整理2

  categories:nginx  author:

原创文章,转载请指明出处并保留原文url地址

本文主要针对nginx的几个主要基础指令做一个简单的整理,另外部分指令做了实际测试,本文具体包括如下指令:

client_body_timeoutclient_header_buffer_sizeclient_header_timeoutclient_max_body_sizeconnection_pool_sizedefault_type

8. client_body_timeout 

syntax:

client_body_timeout    time;

default:

client_body_timeout 60s;

context:

http, server, location

定义一个客户端读取请求的超时时间,具体就是两次成功的读取操作自己的时间间隔不能超过这个时间,例如若是超时时间设置为60秒钟, 当nginx第一次从用户的请求中读取到数据后,若是连接未关闭,他将等待用户下一次请求,但是若等待60秒钟后没有其他请求导入,他就超时,放回给客户端一个408状态吗,然后关闭连接(文档没写,但是推测应该是关闭)。

另外,这个时间是不包括从连接中读取请求body的具体时间。例如读取一个特别大的上传文件比如2G,也不受这个时间影响,这时间是从开始等待的时刻开始记录的,一旦在等待时间范围内有了数据就不在计算了。

原文如下:

Defines a timeout for reading client request body. A timeout is only set between two successive read operations, not for the transmission of the whole request body. If a client does not transmit anything within this time, the client error 408 (Request Time-out) is returned.

9. client_header_buffer_size

syntax:

client_header_buffer_size   size;

default:

client_header_buffer_size 1k;

context:

http, server

 

设置读取用户请求头的缓存区大小,默认是1K, 一般说1K是足够的,但是对应wap或者有比较长的cookies的情况下这个默认的1k就是不购的,需要配置一下。

Nginx官方解释如下:

Sets buffer size for reading client request header. For most requests, a buffer of 1K bytes is enough. However, if a request includes long cookies, or comes from a WAP client, it may not fit into 1K. If a request line, or a request header field do not fit entirely into this buffer then larger buffers are allocated, configured by the large_client_header_buffers directive.

10. client_header_timeout

syntax:

client_header_timeout   time;

default:

client_header_timeout 60s;

context:

http, server

client_body_timeout 非常相似,仅仅这次是读取用户的请求头,而不是body

Nginx官方解释如下:

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

11. client_max_body_size

syntax:

client_max_body_size  size;

default:

client_max_body_size 1m;

context:

http, server, location

设置最大允许的客户端请求body尺寸,通过指定headerContent-Length字段的大小来实现。如果超过配置量,客户端将会收到一个413的错误信息(请求太大了)。请注意目前浏览器不能正常显示这个错误信息!

这个设置对文件上传有很大的影响,特别是大文件上传!

Nginx官方解释如下:

Sets the maximum allowed size of the client request body, specified in the “Content-Length” request header field. If it exceeds the configured value, the client error 413 (Request Entity Too Large) is returned. Please be aware that browsers cannot correctly display this error. Setting size to 0 disables client request body size checking. 

12. connection_pool_size

syntax:

connection_pool_size   size;

default:

connection_pool_size 256;

context:

http, server

允许微调每个连接内存分配。这个指令对性能的影响很小,一般不应使用。

Nginx官方解释如下:

Allows to fine tune per-connection memory allocations. This directive has minimal impact on performance, and should not generally be used.

13. default_type

syntax:

default_type   mime-type;

default:

default_type text/plain;

context:

http, server, location

 定义一个默认响应的MIME类型。可以设置MIME类型文件扩展名映射指令。

Nginx官方解释如下:

Defines a default MIME-type of a response. Mapping of file name extensions to MIME types can be set with the types directive.



快乐成长 每天进步一点点