对于 MP4,FLV 等媒体文件,参考配置
sendfile on;
sendfile_max_chunk 16m;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 30;
Syntax: 句法: send_timeout time;
Default: 默认:
send_timeout 60s;
Context: 语境: http, server, location
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.
设置向客户端传输响应的超时。仅在两个连续的写入操作之间设置超时,而不是为整个响应的传输设置超时。如果客户端在这段时间内没有收到任何内容,则连接将关闭。
Syntax: 句法: sendfile on | off;
Default: 默认:
sendfile off;
Context: 语境: http, server, location, if in location
Enables or disables the use of sendfile().
启用或禁用 sendfile() 的使用。
Starting from nginx 0.8.12 and FreeBSD 5.2.1, aio can be used to pre-load data for sendfile():
从 nginx 0.8.12 和 FreeBSD 5.2.1 开始,aio 可用于预加载 sendfile() 数据:
location /video/ {
sendfile on;
tcp_nopush on;
aio on;
}
In this configuration, sendfile() is called with the SF_NODISKIO flag which causes it not to block on disk I/O, but, instead, report back that the data are not in memory. nginx then initiates an asynchronous data load by reading one byte. On the first read, the FreeBSD kernel loads the first 128K bytes of a file into memory, although next reads will only load data in 16K chunks. This can be changed using the read_ahead directive.
在此配置中,使用 SF_NODISKIO 标志调用 sendfile() ,这会导致它不会阻塞磁盘 I/O,而是报告数据不在内存中。然后,nginx 通过读取一个字节来启动异步数据加载。第一次读取时,FreeBSD 内核会将文件的前 128K 字节加载到内存中,但下一次读取只会加载 16K 块中的数据。这可以使用 read_ahead 指令进行更改。
Before version 1.7.11, pre-loading could be enabled with aio sendfile;.
在 1.7.11 版本之前,可以使用 aio sendfile; 启用预加载。
Syntax: 句法:sendfile_max_chunk size;
Default: 默认:
sendfile_max_chunk 2m;
Context: 语境: http, server, location
Limits the amount of data that can be transferred in a single sendfile() call. Without the limit, one fast connection may seize the worker process entirely.
限制单个 sendfile() 调用中可以传输的数据量。如果没有限制,一个快速连接可能会完全占用工作进程。
Prior to version 1.21.4, by default there was no limit.
在 1.21.4 版本之前,默认情况下没有限制。