Nginx,sendfile和FastCGI

时间:2015-11-06 10:48:56

标签: nginx fastcgi

如果nginx仅配置为将请求转发到FastCGI后端(Mono,PHP等),而不涉及任何基于文件的缓存,那么在nginx.conf中使用sendfile on会带来任何性能改进吗?

示例nginx.conf:

worker_processes  1;
daemon off;

events {
    worker_connections  1024;
    use epoll;
}

http {
    sendfile        on; # <-- ???
    tcp_nopush      on;
    tcp_nodelay     on;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /usr/aspnet/;
            fastcgi_pass 127.0.0.1:9000;
            include /etc/nginx/nginx-fastcgi-params.conf;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

来自Sendfile man pages

  

ssize_t sendfile(int out_fd,int in_fd,off_t * offset&#34;,size_t&#34;&#34; count&#34;);
  ....
  in_fd参数必须对应于支持类似mmap(2)的操作的文件(即,它不能是套接字)。

换句话说,启用sendfile不会产生任何差别,除非nginx正在读取可以像文件一样映射到虚拟内存空间的东西。因此,使用fastcgi_pass不会对性能产生任何影响。