'没有指定input文件'错误 – NginX / fcgi – 请求不存在的.php文件时

我有NginX使用fcgi为drupal站点提供服务。 试图浏览到一个不存在的PHP文件(例如www.example.com/this-file-doesn't-exist.php)会导致出现此错误的白屏:

'没有指定input文件'

我用这个post来帮我设置NginX: http : //drupal.org/node/110224

这是我的NginXconfiguration文件:

server { listen 1.2.3.4:80 default; server_name www.example.com; client_max_body_size 6M; root /var/www/example.com/; index index.php; error_page 404 /index.php; error_page 403 /403.html; # set up a location to serve static images for static error pages location ^~ /error_images/ { root /var/www/static_pages/error_pages; access_log off; expires 30d; } # use our own custom 403 page location = /403.html { root /var/www/static_pages/error_pages; } # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root /var/www/static_pages/error_pages; } location / { error_page 404 index.php; error_page 403 /403.html; # the main drupal app if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; } } # hide protected files location ~* \.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)$ { deny all; } # serve static files directly location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ { rewrite ^/favicon.ico$ /sites/example.com/themes/exampletheme/favicon.ico break; access_log off; expires 30d; } # imagecache needs to have php read any files that it's planning to manipulate location ^~ /sites/example.com/files/imagecache/ { index index.php index.html; # assume a clean URL is requested, and rewrite to index.php if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?q=$1 last; break; } } # serve the app via fastcgi location ~ \.php$ { # ensure that a 404 is returned if a non existant php file is requested # doesn't seem to work properly, so commenting out # fastcgi_intercept_errors on; fastcgi_pass unix:/tmp/php-fastcgi.sock; fastcgi_index index.php; fastcgi_read_timeout 240; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } 

这篇文章http://forum.slicehost.com/comments.php?DiscussionID=1259表明它可能是一个权限错误。 但是,我以用户的身份启动fcgi:组nginx:nginx,这与NginX运行的用户相同。

一般情况下,configuration工作得很好,而且网站的工作原理是100%。 只有在请求一个不存在的.php文件时才会出现问题。 请求一个不存在的.html文件,例如导致Drupal提供404错误页面 – 这也是我想为不存在的.php文件发生的事情。

PS。 如果你想查看那个url,请在http://之后删除多余的空格。 – 我没有足够的代表发布多个超链接!

你可以尝试使用try_file来代替。

见NGinx最佳实践

例如对于wordpress。 相应地适应。

 location /wordpress { try_files $uri $uri/ @wordpress; } location @wordpress { fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^(/wordpress)(/.*)$; fastcgi_param SCRIPT_FILENAME /var/www/wordpress/index.php; fastcgi_param PATH_INFO $fastcgi_path_info; } 

这个错误实际上是由PHP比fastcgi造成的。 你用apache得到相同的响应。 您可以让您的networking服务器在发送到php之前检查文件是否存在。 有了Apache,你可以使用mod_rewrite来做到这一点,但是我不太了解nginx来帮助你实现它。 另一种方法是查看PHP是否有一个configuration选项,它允许您在找不到请求的php文件时修改行为。

  location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/domain.com/public/$fastcgi_script_name; include fastcgi_params; } 

这个configuration适合我。

我也有同样的问题。 我只是在行中添加了我的web根目录

  SCRIPT_FILENAME /web/root/$fastcgi-script_name; 

现在它像一个魅力工作。

请在fastcgi_params中包含以下行

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;