ngx_http_core_module模块基本指令整理5

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

本文主要针对nginx的ngx_http_core_module模块做简单介绍,本文具体包括如下指令:

keepalive_timeout,large_client_header_buffers,limit_except,limit_rate,limit_rate_after

26. keepalive_timeout

syntax:keepalive_timeout  timeout[header_timeout];
default:keepalive_timeout 75s;
context:http, server, location

第一参数设置一个客户端的连接在server端保持存活的超时时间。这个参数若是为0则禁止客户端的keep-alive的连接。可选第二个参数用来在http相应头中设置一个字段,字段名称keep-alive,字段值为:header_timeout, 结果为Keep-Alive: timeout=header_timeout。这个两个参数值可以不一样。

“Keep-Alive: timeout=time”头字段是由Mozilla和Konqueror理解。ie将大约60秒钟内关闭保持的连接。

原文如下:

The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The value of zero 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 understood by Mozilla and Konqueror. MSIE will close keep-alive connection in about 60 seconds.

27. large_client_header_buffers

syntax:large_client_header_buffers    numbersize;
default:large_client_header_buffers 4 8k;
context:http, server

设置当读取大的客户端请求时缓冲的最大数目和尺寸。在缓冲的一个请求行不能超过这个尺寸。或者客户端414(uri太大请求)信息被返回。一个请求头部域也不能超过buffer的尺寸,或者客户端成收到400(坏的请求)信息。缓冲仅在被需要时才创建。默认的buffer的尺寸是8k字节。如果请求的处理接受后,处理连接被转换成keep-alive状态,缓冲被释放。

Nginx官方解释如下:

Sets the maximum number and size of buffers used when reading large client request header. A request line cannot exceed the size of one buffer, or the client error 414 (Request-URI Too Large) is returned. A request header field cannot exceed the size of one buffer as well, or the client error 400 (Bad Request) is returned. Buffers are allocated only on demand. By default, the buffer size is equal to 8K bytes. If after the end of request processing a connection is transitioned into the keep-alive state, these buffers are freed.

28. limit_except

syntax:limit_except   method... { ... }
default:
context:location

现在在一个location配置中允许的内置方法。这个方法参数可以是下面参数:GET, HEAD, POST, PUT, DELETE, MKCOL, COPY, MOVE, OPTIONS, PROPFIND, PROPPATCH, LOCK, UNLOCK, or PATCH。运行Get方法也允许Head方法。到其他方法的访问能够采用ngx_http_access_module和ngx_http_auth_basic_module指令来限定。例如:

limit_except GET {

allow 192.168.1.0/32;

deny  all;

}

注意这将限制除了Get外的方法。

Nginx官方解释如下:

Limits allowed HTTP methods inside a location. The method parameter can be one of the following: GET, HEAD, POST, PUT, DELETE, MKCOL, COPY, MOVE, OPTIONS, PROPFIND, PROPPATCH, LOCK, UNLOCK, or PATCH. Allowing the GET method also allows the HEAD method. Access to other methods can be limited using the ngx_http_access_module and ngx_http_auth_basic_module modules directives:

limit_except GET {

allow 192.168.1.0/32;

deny  all;

}

Please note that this will limit access to all methods except GET and HEAD.

29. limit_rate

syntax:limit_rate   rate;
default:limit_rate 0;
context:http, server, location, if in location

向客户端相应的传输速度限制。这个速率制定的单位是 字节/秒钟。 特殊值0禁止这个速度值限制。该限制是针对每个请求的, 为此假设一个客户端模拟打开两个客户端连接,总的被现在的速度将是制定速率的2被。

速度也能用$limit_rate变量来设置。当速度限制在一个特定的条件下发生时,这种现实是比较好的。例如:

server {

if ($slow) {

set $limit_rate 4k;

}

...

}

另外这个速度限制也能在X-Accel-Limit-Rate相应头中指令中进行控制。本指令的功能能够通过proxy_ignore_headers指令来限制。

Nginx官方解释如下:

Rate limits the transmission of a response to a client. The rate is specified in bytes per second. The value 0 disables rate limiting. The limit is set per request, so if a client simultaneously opens two connections, an overall rate will be twice as much as the specified limit.

Rate limit can also be set in the $limit_rate variable. It may be useful in cases where rate should be limited depending on a certain condition:

server {

if ($slow) {

set $limit_rate 4k;

}

...

}

In addition, rate limit can also be set in the “X-Accel-Limit-Rate” header field of a proxied server response. This ability can be disabled using the proxy_ignore_headers and fastcgi_ignore_headers directives.

30. limit_rate_after

syntax:limit_rate_after    size;
default:limit_rate_after 0;
context:http, server, location, if in location

设置初始之后,对客户端的进一步相应的速度限制。例如:

location /flv/ {

flv;

limit_rate_after 500k;

limit_rate       50k;

}

Nginx官方解释如下:

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

location /flv/ {

flv;

limit_rate_after 500k;

limit_rate       50k;

}

发表评论