Windows 上的 NGINX 和 php-cgi“未指定輸入檔”

Windows 上的 NGINX 和 php-cgi“未指定輸入檔”

我正在運行 php-cgi 和 NGINX。它們在一個資料夾中運行,但它們的根目錄位於 2 個目錄外,2 個目錄內。當根目錄為 html(預設)時,它們運作得很好,但是現在 php 報告「未指定輸入檔案」錯誤。我嘗試設定目錄以完全控制所有程序,我已經完全控制,我嘗試查看 php 是否在不同的目錄中查找,嘗試更改目錄,對 php 變數進行硬編碼等。解決這個問題,但沒有一個能夠解決它。控制台中沒有錯誤,我的 fastcgi.conf 沒有更改。 php 和 NGINX 都確實在運行和通信,但是 php 由於某種原因無法取得檔案。當訪問任何非 php 檔案時,NGINX 成功檢索該檔案並且我的瀏覽器顯示它。我已經使用 netstat 驗證了,唯一在連接埠 9100 上偵聽的是我的 php-cgi。唯一監聽 8080 埠的是 NGINX。 php 和 NGINX 都配置為正確通信,並且 php-cgi 透過 php 目錄中的 RunHiddenConsole.exe 運行。

這是目錄樹,格式類似 YAML:

EclipsePHP
    - Code
        - Blog
            - Source (NGINX/php root Location/Website Source Files)
    - NGINX
        - 1.9.11 (NGINX Executable Location)
            - php (php Executable Location)

還有我的 nginx.conf

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


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

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        root   ../../Code/Blog/Source;
        client_max_body_size 5G;
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            index  index.php;
            try_files $uri $uri.html $uri/ @extensionless-php;
            index index.html index.htm index.php;
            client_max_body_size 5G;
        }

        error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #

        recursive_error_pages off;

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            client_max_body_size 5G;
            try_files      $uri =404;
            include        fastcgi.conf;
            include        fastcgi_params;
            fastcgi_pass   127.0.0.1:9100;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}

        location @extensionless-php {
             rewrite ^(.*)$ $1.php last;
        }
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

導致此錯誤的原因是什麼? (我正在使用 Eclipse PHP 編輯原始程式碼,無論運行或不運行 Eclipse 都會出現錯誤。)

答案1

由於php不喜歡相對目錄,我的解決方案是每次啟動時使用批次設定絕對目錄。在啟動 NGINX 之前,我在批次啟動腳本中插入了以下內容。

set TEXT_FILE=conf\phploc.conf
set REL_PATH=..\..\Code\Blog\Source
set ABS_PATH=
pushd %REL_PATH%
set ABS_PATH=%CD%
popd
echo fastcgi_param  SCRIPT_FILENAME  %ABS_PATH%$fastcgi_script_name; > %TEXT_FILE%

然後在 NGINX 設定檔中,我在 php 位置區塊中插入以下內容以載入目錄設定。

include phploc.conf;

答案2

您將根定義為相對路徑,該路徑相對於nginx配置目錄。

然後將其傳遞給php-cgi,它可能不關心nginx其文件保存在哪裡。所以無法解決../../

您應該指定一個絕對根。

相關內容