(1) sendfile 參數用於開啟文件的高效傳輸模式,該參數實際上是激活了 sendfile() 功能,sendfile() 是作用於兩個文件描述符之間的數據拷貝函數,這個拷貝操作是在內核之中的,被稱為 "零拷貝" ,sendfile() 比 read 和 write 函數要高效得多,因為 read 和 write 函數要把數據拷貝到應用層再進行操作
(2) tcp_nopush 參數用於激活 Linux 上的 TCP_CORK socket 選項,此選項僅僅當開啟 sendfile 時才生效,tcp_nopush 參數可以允許把 http response header 和文件的開始部分放在一個文件里發布,以減少網絡報文段的數量
cat /usr/local/nginx/conf/nginx.conf
......
http {
include mime.types;
server_names_hash_bucket_size 512;
default_type application/octet-stream;
sendfile on; # 開啟文件的高效傳輸模式
tcp_nopush on; # 激活 TCP_CORK socket 選擇
tcp_nodelay on; #數據在傳輸的過程中不進緩存
keepalive_timeout 65;
server_tokens off;
include vhosts/*.conf;
}
作者簡介:
陳志珂(頭條號:強扭的瓜不好吃)公眾號“鉛筆學園”運維內容合作作者之一,目前就職於中國最大的安卓應用軟件公司,任高級工程師,現在公司任php開發工程師,python開發工程師,高級運維工程師。
鉛筆學園:IT資源分享|知識分享,做初級程序員的指明燈