一千萬個為什麽

搜索

'無輸入文件指定'錯誤 - NginX/fcgi - 請求不存在的.php文件時

我讓NginX使用fcgi服務於drupal站點。嘗試瀏覽到不存在的php文件(例如www.example.com/this-file-doesn't-exist.php)會導致出現此錯誤的白屏:

'沒有指定輸入文件'

I used this post to help me set it up 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 nginx:nginx,它與NginX運行的用戶相同。

一般來說,配置工作正常,網站100%正常工作。只有在請求不存在的.php文件時才會出現問題。例如,請求一個不存在的.html文件導致Drupal服務於它的404錯誤頁面 - 這也是我想要存在的非存在的.php文件。

PS。如果你想查看那個網址,請在http://之後刪除多余的空格 - 我沒有足夠的代表來發布多個超鏈接!

最佳答案

您可以嘗試使用try_file。

See 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;
}

轉載註明原文: '無輸入文件指定'錯誤 - NginX/fcgi - 請求不存在的.php文件時