Nginx sendfile作用

sendfile位置

查看nginx.conf文件 标黄位置

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
	server_names_hash_bucket_size 128;
	#请求行+请求头的标准大小
	client_header_buffer_size 16k;
	#请求行+请求头的最大大小 4*16k
	large_client_header_buffers 4 16k;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
		
    #access_log  logs/access.log  main;
    **sendfile        on;**
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;



    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    #include vhosts.conf;
    #include vhosts/*.conf;
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
	server {
        listen       8085;   
		server_name  localhost dev.heating.com;
		location /man {
            proxy_pass http://127.0.0.1:8405/;
			proxy_set_header       X-Real-IP $remote_addr;  
			proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header       X-Forwarded-For $http_x_forwarded_for;
        }
		location /fs {
			proxy_pass http://127.0.0.1:8080/;
			proxy_set_header       X-Real-IP $remote_addr;  
			proxy_set_header       X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header       X-Forwarded-For $http_x_forwarded_for;
		}
        location / {
            root   D:\heating\dist;
            index  index.html index.htm;
        }
	      		
    }
client_max_body_size 50m;
}

网络文件传输
1.工作原理图
在这里插入图片描述

2. 工作原理描述:
sendfile = off 时,应用程序读取磁盘中的文件以字节流的形式从磁盘中加载文件,然后再将文件以字节流的形式复制到内核中。内核在把文件推送到NC。
sendfile = on 时,应用程序直接向内核发送指令,让内核去读文件。读完文件内核直接推送给NC。只有一次复制操作,实现异步网络IO形式。因此,性能会有很大的提升。
具体还要根据实际使用情况来配置sendfile。当读取服务不能解析大量的文件时。还是建议将sendfile配置为off

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值