데비안의 PHP+FastCGI+nginx

데비안의 PHP+FastCGI+nginx

저는 데비안을 처음 사용합니다. 데비안에서 PHP를 사용하고 싶습니다. 나는 다음을 원한다:

apt-get install php5-cli php5-cgi spawn-fcgi

파일 만들기 /usr/bin/php-fastcgi:

#! /bin/sh
PHP_FCGI_CHILDREN=3
PHP_FCGI_MAX_REQUESTS=1000
exec /usr/bin/php5-cgi

파일 만들기 /etc/init.d/init-fastcgi:

#!/bin/bash
PHP_SCRIPT="/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -g www-data -f     /usr/bin/php-fastcgi"
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php5-cgi
RETVAL=$?
;;
restart)
killall -9 php5-cgi
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: sudo /etc/init.d/init-fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL

Atel은 다음을 수행합니다.

chmod 755 /usr/bin/php-fastcgi
chmod 755 /etc/init.d/init-fastcgi 

들어가서 /etc/nginx/sites-enabled/default다음을 추가하세요:

location ~\.php$ {
 root /srv/www/ekb.mydomain.com/public_html;
 include /etc/nginx/fastcgi_params;
 fastcgi_pass 127.0.0.1:9000;
 fastcgi_index index.php;
 fastcgi_param QUERY_STRING $query_string;
 fastcgi_param SCRIPT_FILENAME /srv/www/ekb.mydomain.com/public_html$fastcgi_script_name;
}

디렉터리를 생성합니다:

/srv/www/ekb.mydomain.com/public_html
/srv/www/ekb.mydomain.com/logs

파일 만들기/srv/www/ekb.mydomain.com/public_html/test.php

<?phpinfo();?>

서비스를 시작합니다:

/etc/init.d/init-fastcgi start
/etc/init.d/nginx start

브라우저에서:

 www.ekb.maydomain.com/test.php 

그런데 404에러가 발생합니다.

내가 뭘 잘못했나요?

답변1

nginx를 구성하려면 php-fpm을 사용해야 합니다. 설치, 구성, 관리가 더 쉽고 빠릅니다.

$ apt-get install nginx php5-fpm
$ nano /etc/nginx/nginx.conf

[...]
worker_processes  4;
[...]
keepalive_timeout   2;
[...]


$ nano /etc/nginx/sites-available/default

[...]
server {
    listen   80; ## listen for ipv4; this line is default and implied
    listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /usr/share/nginx/www;
    index index.php index.html index.htm;

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            allow ::1;
            deny all;
    }

    # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests
    #location /RequestDenied {
    #       proxy_pass http://127.0.0.1:8080;
    #}

    #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 /usr/share/nginx/www;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            try_files $uri =404;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

            # With php5-cgi alone:
            #fastcgi_pass 127.0.0.1:9000;
            # With php5-fpm:
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

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

nginx와 php-fpm을 시작합니다:

$ service nginx start
$ service php5-fpm start

답변2

/etc/hosts다음과 같이 localhost 줄을 편집하고 추가해 보세요 .

127.0.0.1    localhost ekb.maydomain.com

즉, ekb.maydomain.comwhich로 시작하는 줄에 추가하세요 127.0.0.1. 이 줄과 정확히 같지 않을 수도 있습니다.

문제는 "www.ekb.maydomain.com"이 실제 www 주소이고 DNS 확인자가 이를 찾을 수 없다는 것입니다. 이 줄을 에 추가하면 /etc/hosts도메인에 대한 DNS 확인을 건너뛰고 대신 이를 localhost브라우저가 실제로 동일한 컴퓨터에서 실행 중인 웹 서버를 찾을 수 있는 별칭으로 사용할 수 있습니다.

관련 정보