性能优化-开启高效文件传输模式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

 nginx优化开启高效文件传输模式sendfile        on;_nginx优化

(3) 设置参数 tcp_nodelay on 说明:有时要抓紧发货, 确保数据尽快发送, 提高可数据传输效率

   参数语法 tcp_nodelay on | off;

   放置位置  httpserverlocation

nginx优化开启高效文件传输模式sendfile        on;_nginx优化_02nginx优化开启高效文件传输模式sendfile        on;_nginx优化_03

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;
}