‘无输入文件指定’错误 – NginX/fcgi – 请求不存在的.php文件时

前端之家收集整理的这篇文章主要介绍了‘无输入文件指定’错误 – NginX/fcgi – 请求不存在的.php文件时前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我让Nginx使用fcgi服务于drupal站点.尝试浏览到不存在的PHP文件(例如www.example.com/this-file-doesn’t-exist.PHP)会导致出现此错误的白屏:

‘没有指定输入文件

我用这篇文章帮我设置了Nginx
http://drupal.org/node/110224

这是我的Nginx配置文件

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:group NginxNginx,它与Nginx运行的用户相同.

一般来说,配置工作正常,网站100%正常工作.只有在请求不存在的.PHP文件时才会出现问题.例如,请求一个不存在的.html文件导致Drupal服务于它的404错误页面 – 这也是我想要存在的非存在的.PHP文件.

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

最佳答案
您可以尝试使用try_file.

NGinx Best Practices

例如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;
}
原文链接:https://www.f2er.com/nginx/435154.html

猜你在找的Nginx相关文章