我最近开始使用带有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"
做了一些研究并确保文档根目录在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;
}
}
}
提前感谢大家。
答案 0 :(得分:5)
这可能发生在PHP-FPM尝试打开PHP文件时,触及有关打开文件的rlimit并返回404。
以下是strace(complete strace output)的相关部分:
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
因此,您可以编辑rlimit_files或系统配置,让PHP-FPM打开更多文件。
答案 1 :(得分:2)
我遇到了同样的问题,并在日志中找到了这个提示:
open_basedir restriction in effect
所以我要做的就是将phpmyadmin所在的文件夹添加到php.ini
的列表中。
答案 2 :(得分:0)
我遇到了同样的问题,我发现解决方案与https://superuser.com/questions/787888/too-many-files-open-on-mac-osx-after-running-apache-in-php-with-xdebug-for-som
相同xdebug中存在一个错误,它没有正确关闭文件,所以你达到了极限。如果停用远程调试,则此错误不再出现。
现在我已将xdebug.remote_enable
设置为开启,xdebug.remote_autostart
设置为关闭,以防我想通过这个方便的Chrome扩展程序调试我正在调试的内容:https://chrome.google.com/webstore/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc