nginx、php-cgi 和「未指定輸入檔」。

nginx、php-cgi 和「未指定輸入檔」。

我試著讓 nginx 與 php-cgi 很好地配合,但它並沒有按照我想要的方式運作。我使用一些設定變數來允許動態主機名稱——基本上是anything.local。我知道這些東西正在工作,因為我可以正確存取靜態文件,但是 php 文件不起作用。我得到標準的“未指定輸入檔”。當檔案不存在時通常會發生錯誤,但它確實存在且路徑是正確的,因為我可以存取同一路徑中的靜態檔案。這可能是權限問題,但我不確定這怎麼會成為一個問題。我在 Windows 上用我自己的用戶帳戶運行它,所以我認為它應該有權限,除非 php-cgi 在我沒有告訴它的情況下在不同的用戶下運行。 >.>

這是我的配置;

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    keepalive_timeout  65;
 gzip  on;

 server {
  # Listen for HTTP
  listen 80;

  # Match to local host names.
  server_name  *.local;

  # We need to store a "cleaned" host.
  set $no_www $host;
  set $no_local $host;

  # Strip out www.
  if ($host ~* www\.(.*)) {
   set $no_www $1;
   rewrite ^(.*)$ $scheme://$no_www$1 permanent;
  }

  # Strip local for directory names.
  if ($no_www ~* (.*)\.local) {
   set $no_local $1;
  }

  # Define default path handler.
  location / {
   root   ../Users/Stephen/Documents/Work/$no_local.com/hosts/main/docs;
   index  index.php index.html index.htm;

   # Route non-existent paths through Kohana system router.
   try_files $uri $uri/ /index.php?kohana_uri=$request_uri;
  }

  # pass PHP scripts to FastCGI server listening on 127.0.0.1:9000
  location ~ \.php$ {
   root   ../Users/Stephen/Documents/Work/$no_local.com/hosts/main/docs;
   fastcgi_pass   127.0.0.1:9000;
   fastcgi_index  index.php;
   include        fastcgi.conf;
  }

  # Prevent access to system files.
  location ~ /\. {
   return 404;
  }
  location ~* ^/(modules|application|system) {
   return 404;
  }
 }
}

答案1

沒關係,我已經弄清楚了。

Windows 版本的 nginx 將根路徑附加到可執行路徑,因此如果它位於 C:\nginx 並且您想要將檔案儲存在 C:\www 中,則需要對根路徑執行 ../www 。 Nginx 將其奇怪的轉換路徑傳遞給 PHP,但 PHP 無法理解它,因此我將其調整為使用絕對路徑。

相關內容