Windows의 NGINX 및 php-cgi "입력 파일이 지정되지 않았습니다"

Windows의 NGINX 및 php-cgi "입력 파일이 지정되지 않았습니다"

저는 php-cgi와 NGINX를 실행하고 있습니다. 그들은 폴더에서 실행되고 있지만 루트 디렉터리는 2개의 디렉터리이고 거기에서 2개의 디렉터리입니다. 루트가 html(기본값)이면 완벽하게 작동했지만 이제 PHP는 "지정된 입력 파일 없음" 오류를 보고합니다. 나는 모든 프로그램에 모든 권한을 부여하기 위해 디렉토리를 설정해 보았고 이미 모든 권한을 갖고 있으며 PHP가 다른 디렉토리를 찾고 있는지 확인하고 디렉토리를 변경하고 PHP 변수를 하드 코딩하는 등의 작업을 시도했습니다. 이 문제를 해결하는 방법에 대해 약 5개의 다른 튜토리얼을 따랐지만 아무도 해결하지 못했습니다. 콘솔에는 오류가 없으며 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;
    #    }
    #}

}

이 오류의 원인은 무엇이며 브라우저에서 PHP 파일을 제대로 볼 수 있도록 해결하려면 어떻게 해야 합니까? (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그래서 해결할 수 없습니다 ../../.

절대 루트를 지정해야 합니다.

관련 정보