1. 程式人生 > >nginx 開啟高效檔案傳輸模式

nginx 開啟高效檔案傳輸模式

(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資源分享|知識分享,做初級程式設計師的指明燈
這裡寫圖片描述