在Nginx和php-fpm中随机指定"无输入文件"

Pet*_* Au 2 php nginx

我最近开始使用带有php-fpm的Nginx.一切似乎都没问题,除了偶尔我得到"没有指定输入文件"和404.登录access.log.它似乎是随机的,其中一个请求获得200,而另一个请求到同一个文件获得404上述错误.在Nginx和php-fpm error.log中都没有发现相关错误.

这是access.log的摘录:

10.0.0.5 - - [09/Aug/2011:18:14:27 -0400]  200 "POST /services/ChangeAccount HTTP/1.1" 110 "http://slotspot-internal.blitzoo.com/" "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" "94.49.122.184"
10.0.0.5 - - [09/Aug/2011:18:15:27 -0400]  404 "POST /services/ChangeAccount HTTP/1.1" 36 "http://slotspot-internal.blitzoo.com/" "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" "94.49.122.184"
10.0.0.5 - - [09/Aug/2011:18:15:28 -0400]  200 "POST /services/ChangeAccount HTTP/1.1" 110 "http://slotspot-internal.blitzoo.com/" "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0" "94.49.122.184"
Run Code Online (Sandbox Code Playgroud)

做了一些研究并确保文档根目录在Nginx配置服务器块中定义,fastcgi_param SCRIPT_FILENAME定义为$ document_root $ fastcgi_script_name

这是我的nginx.conf:

user       nginx nginx;
worker_processes  5;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
worker_rlimit_nofile 8192;

events {
  worker_connections  4096;
}

http {
  include    /etc/nginx/mime.types;
  include    /etc/nginx/proxy.conf;
  include    /etc/nginx/fastcgi.conf;
  index    index.html index.htm index.php;

  default_type application/octet-stream;
  log_format   main '$remote_addr - $remote_user [$time_local]  $status '
    '"$request" $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';
  access_log   /var/log/nginx/access.log main;
  sendfile     on;
  tcp_nopush   on;
  server_names_hash_bucket_size 128; # this seems to be required for some vhosts


  server {
     listen       80;
     server_name  _;
     root   /opt/myapp/current/server/public;

     location / {
         root   /opt/myapp/current/server/public;
         index  index.php index.html index.htm;
     }

     error_page  404         /404.html;
     location = /404.html {
         root   /usr/share/nginx/html;
     }

     # redirect server error pages to the static page /50x.html
     #
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
        root   /usr/share/nginx/html;
     }

     # deny access to .htaccess files, if Apache's document root
     # concurs with nginx's one
     #
     location ~ /\.ht {
         deny  all;
     }

     location ~ /admin {
     rewrite   ^/admin(.*)$ /router.php last;
     }
     location ~ /index/ {
     rewrite   ^/index/(.*)$ /router.php last;
     }
     location ~ /services/ {
     rewrite   ^/services/(.*)$ /router.php last;
     }
     location ~ /skupdater/ {
     rewrite   ^/skupdater/(.*)$ /router.php last;
     }

     location ~ \.php$ {
     root           /opt/myapp/current/server/public;
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     include        fastcgi_params;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     fastcgi_param  PATH_INFO $fastcgi_script_name;
     }

  }
}
Run Code Online (Sandbox Code Playgroud)

提前谢谢大家.

Jul*_*ard 5

这可能发生在PHP-FPM尝试打开PHP文件时,触及有关打开文件的rlimit并返回404.

以下是一个strace的相关部分(完整的strace输出):

open("/home/julien/www/shape/engine/index.php", O_RDONLY) = -1 EMFILE (Too many open files)
write(4, "\1\6\0\1\0d\4\0Status: 404 Not Found\r\nX"..., 128) = 128
Run Code Online (Sandbox Code Playgroud)

因此,您可以编辑rlimit_files或系统配置,以便让PHP-FPM打开更多文件.