最近為了要用 X-Sendfile 的功能。

所以要用PHP來接Request,然後透過X-Sendfile 來轉送實際的檔案。

醬子,檔案的實體路徑就不容易被看出來了。

所以要裝一下PHP

安裝NGINX的部份就不多說了。

php的話,就

#zypper in php5
#zypper in php5-fastcgi

這部份還挺簡單的。

但接著就比較麻煩了。

我們要自己啟動php-cgi

這個要利用到 spawn 就會比較容易了 ( 感謝小粉紅 )

可以加入這個Repository,然後再使用zypper in spawn-fcgi來安裝。

# zypper addrepo --name "openSUSE-11.4" http://download.opensuse.org/distribution/11.4/repo/oss/suse/ repo-11.4
# zypper ref
# zypper se spawn-fcgi
# zypper in spawn-fcgi

裝完後,接著就要在/etc/init.d/ 加一個啟動檔。

# vi /etc/init.d/spawn-fcgi

填入以下內容

#! /bin/sh
# Source SuSE config (if still necessary, most info has been moved)
. /etc/rc.status
FCGI_BIN=/usr/bin/spawn-fcgi
test -x $FCGI_BIN || exit 5
PHPCGI_BIN=/home/php/bin/php-cgi
# First reset status of this service
rc_reset
case "$1" in
    start)
        echo -n "Starting PHP-CGI"
        # 也可以用下面這種方式。
        #startproc $FCGI_BIN -a 127.0.0.1 -C 5 -p 9000 -f /usr/bin/php-cgi
        startproc /usr/bin/sudo -u wwwrun $FCGI_BIN -C 32 -s /tmp/spawn.sock -f $PHPCGI_BIN
        ;;
    stop)
        echo -n "Stopping PHP_CGI"
        killproc -TERM $PHPCGI_BIN
        rc_status -v
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    status)
        echo -n "Checking for service PHP-CGI: "
        checkproc $PHPCGI_BIN
        rc_status -v
        ;;

    *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
        ;;
esac
rc_exit

接著

# chomd +x /etc/init.d/spawn-fcgi 

然後在 nginx.conf 加上

    location ~\.php$  {
        fastcgi_pass unix:///tmp/spawn.sock;
        fastcgi_buffer_size 32k;
        fastcgi_buffers 32 32k;
        include fastcgi.conf;
    }

搞定~收工。

arrow
arrow
    全站熱搜

    Ching-Wei 發表在 痞客邦 留言(0) 人氣()