php-fpm을 사용하는 nginx는 Mac OS X(로컬 환경)에서 실행하는 대신 PHP 파일을 다운로드합니다.

php-fpm을 사용하는 nginx는 Mac OS X(로컬 환경)에서 실행하는 대신 PHP 파일을 다운로드합니다.

로컬 개발 컴퓨터에서 PHP 파일을 실행하는 데 문제가 있습니다. 성공적으로 설치한 것 같습니다.nginx그리고PHP-FPM또한 올바르게 설치되어 실행 중인 것 같지만 PHP 파일이 실행되지 않고 다운로드되는 이유를 잘 알 수 없습니다.

수많은 시간이 흐른 후좌절, 이전에 이런 일을 해본 적이 있는 사람에게 물어보는 것이 가장 좋다고 생각했습니다! 모든 정보를 제공하기 위해 최선을 다했지만, 도움이 될 만한 내용이나 제가 놓친 내용이 있다면,주저하지 말고 물어보세요댓글에.

참고:내가 겪고 있는 문제에 대해 주의 깊게 읽어 보세요. 제가 이렇게 말하는 이유는 Google에서 제공할 수 있는 이 문제와 관련된 거의 모든 기사를 읽었으며 여러 가지 방법, 수정, 제안, 재설치, 구성 등을 시도했기 때문입니다. 모두 도움이 되지 못했습니다. 내가 겪고 있는 문제를 수정하거나 디버깅할 수도 있습니다. 즉, 이것은 확실히 중복된 질문이 아닙니다. 확인하기 위해 몇 시간 동안 책을 읽었습니다!

성공적으로 설치했습니다nginx그리고PHP-FPM을 사용하여 https://github.com/josegonzalez/homebrew-php. 믿음직한 선배는 brew doctor모든 것이 최신 상태이고 필요한 모든 것이 설치되어 있음을 확인했습니다(XQuartz, Xcode 명령줄 도구 등).

다음은 내 설정을 이해하는 데 도움이 될 수 있는 일부 파일 발췌입니다.

php-fpm 로그

tail -f /usr/local/var/log/php-fpm.log

[24-Dec-2013 00:05:59] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[24-Dec-2013 00:05:59] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[24-Dec-2013 00:05:59] NOTICE: fpm is running, pid 31745
[24-Dec-2013 00:05:59] NOTICE: ready to handle connections

제가 틀렸다면 정정해 주세요. 하지만 이는 php-fpm이 올바르게 실행되고 있는 것으로 보입니다.

내 php-fpm 구성 파일의 유일한 변경 사항

/usr/local/etc/php/5.4/php-fpm.conf 145번째 줄부터

; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;       will be used.
user = myusername
group = staff

이것을 변경한 이유는 이것이 내 디렉토리 myusername:staff에 user:group이 설정되는 방식이기 때문입니다 . ~이것이 문제의 일부일 수도 있지만 확실하지 않습니다.

나는 실제로 모든 일반적인 파일 권한 문제를 겪었고 /clients/mywebsite/local 내의 모든 파일이 chown -R myusername:staff ./및 를 사용하여 이 문제를 해결했는지 확인할 수 있습니다 chmod -R 0755 ./. 이를 염두에 두고 이것이 권한 문제가 아니기를 바랍니다.

nginx 구성 파일

/usr/local/etc/nginx/nginx.config

#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 {
    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 {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

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

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # 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$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }

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


    # 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;
    #    server_name  localhost;

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

    #    ssl_session_timeout  5m;

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers   on;

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

}

/usr/local/etc/nginx/nginx.conf.default에 있는 원본 파일에서 변경한 유일한 부분은 블록에 index.php를 추가 하고 파일 에 대한 php-fpm 처리를 허용하도록 블록의 location / {주석 처리를 제거한 것입니다.location ~ \.php$ {.php

./usr/local/etc/nginx/conf.d/mywebsite.conf127.0.0.1 mywebsite.localhttp://mywebsite.local

http://mywebsite.local/test.html내 폴더에 있는 파일에 절대 액세스할 수 있으므로 Nginx가 올바르게 설정된 것 같지만 /clients/mywebsite/local/web/test.htmlPHP 파일의 경우에는 이야기가 다릅니다. 브라우저에서 PHP 파일로 다운로드할 뿐 전혀 실행되지 않습니다.

내 웹사이트 구성 파일

/usr/local/etc/nginx/conf.d/mywebsite.conf

server {
    listen   80;
    listen   [::]:80 default ipv6only=on;
    server_name  mywebsite.local;

    location / {
        root   /clients/mywebsite/local/web;
        index  index.php index.html index.htm;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

http://mywebsite.local여기에 있는 모든 부분을 덮어 쓰고 여기에 없는 부분은 일반 파일에서 가져온다고 가정합니다 /usr/local/etc/nginx/nginx.conf.

/usr/local/var/log/nginx/error.log내 파일이 어떤 오류도 반환하지 않는다고 말하는 것도 가치가 있습니다 . 파일을 변경할 때마다 .conf명령을 사용하여 nginx를 다시 시작 하고 프로세스 가 실행 중인지 sudo nginx -s reload확인할 수 있습니다 .php-fpmnginx

또한 내 구성에 없는 것으로 127.0.0.1:9000변경 하는 방법에 대해서도 읽었습니다 . 나는 그것의 존재를 검색하기 위해 사용을 /var/run/php5-fpm/php5-fpm.sock시도했지만 그것은 내 컴퓨터에 없습니다. 또한 이 포트를 이미 사용 중인 경우가 아닌 다른 포트로 변경하는 방법에 대해서도 읽었습니다 . 이것이 첫 번째 설치이기 때문에 이것이 사실이 아닐 것이라고 확신합니다. 그러나 이것을 테스트하려면 어떻게 해야 합니까?findack:9000

나는 또한에 있는 다른 파일에 대해 읽었 /usr/share/nginx/html지만 다시 이것은 존재하지 않습니다.

자, 여기까지 읽어주셔서 감사합니다! 어쨌든 도움을 주실 수 있다면 시간을 내주셔서 정말 감사드립니다.

답변1

nginx.conf 파일에서 PHP 섹션을 지정하는 대신 기본 파일(sites-available 디렉터리 내)에서 서버 위치를 지정하고 nginx를 다시 로드하거나 다시 시작할 수 있습니다.

server { 
        listen 80;
        listen [::]:820; #ipv6only=on;
        root /var/www/;  ##assuming your PHP application is in /var/www/
        index index.php index.html index.htm;
        server_name PHPApp;

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

또한 nginx.conf 파일에 다음 지시어가 있는지 확인하세요.

include /etc/nginx/sites-enabled/*;

답변2

문제는 nginx에게 http 블록에 다음과 같이 PHP 파일을 보낼 위치를 알려주는 업스트림이 없다는 것입니다.

upstream php {
    server unix:/var/run/php-fpm.socket;
}

unix:/var/run/php-fpm.socketPHP 구성의 수신 대기 지시문에 표시되어야 하는 위치 는 다음과 같습니다.

그런데: 좋은 습관은 아닙니다위치 블록 내부의 루트...도 아니다여러 인덱스 지시어.

관련 정보