nginx優化開啓高效文件傳輸模式sendfile on;

性能優化-開啓高效文件傳輸模式sendfile        on;

sendfile        on;   #特殊的數據傳輸功能

tcp_nopush on;

參數sendfile on 用於開啓文件高效傳輸模式,同時將tcp_nopush on tcp_nodelay on 兩個指令設置爲on,可防止網絡及磁盤I/O阻塞,提升Nginx工作效率

(1) 設置參數 sendfile on

   參數語法  sendfile on | off;

   放置位置 httpserverlocationif in location

(2) 設置參數 tcp_nopush on  說明:當有數據時,先彆着急發送, 確保數據包已經裝滿數據, 避免了網絡擁塞

   參數語法 tcp_nopush on | off;

   放置位置 httpserverlocation

 image.png

(3) 設置參數 tcp_nodelay on 說明:有時要抓緊發貨, 確保數據儘快發送, 提高可數據傳輸效率

   參數語法 tcp_nodelay on | off;

   放置位置  httpserverlocation

image.pngimage.png

sendfile on配合使用(2)(3)  (2)(3)只能選其一特別注意

在主配置文件nginx.conf中配置

worker_processes  2;
worker_cpu_affinity 0101 1010;
error_log logs/error.log;
 
#配置Nginx worker進程最大打開文件數
worker_rlimit_nofile 65535;
 
user www www;
events {
    #單個進程允許的客戶端最大連接數
    worker_connections  20480;
    #使用epoll模型
    use epoll;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #sendfile        on;
    keepalive_timeout  65;
    #訪問日誌配置
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
 
 
    #虛擬主機
    include /application/nginx/conf/extra/www.conf;
    include /application/nginx/conf/extra/blog.conf;
    include /application/nginx/conf/extra/bbs.conf;
    include /application/nginx/conf/extra/edu.conf;
    include /application/nginx/conf/extra/phpmyadmin.conf;
    include /application/nginx/conf/extra/status.conf;
 
    #nginx優化----------------------
    #隱藏版本號
    server_tokens on;
 
    #優化服務器域名的散列表大小 
    server_names_hash_bucket_size 64;
    server_names_hash_max_size 2048;
 
    #開啓高效文件傳輸模式
    sendfile on;
    #減少網絡報文段數量
    #tcp_nopush on;
    #提高I/O性能
    tcp_nodelay on;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章