設定 .php 的解析方式
這邊記得要用 Unix domain socket 的模式,比較不會有 "502 Bad Gateway" 錯誤產生。# vim /sites-enabled/default
server {
charset utf-8;
location ~ \.php$
{
try_files $uri $uri/ =404;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/tmp/php-cgi.socket;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
}
}
使用 spawn-fcgi 來管理 php-cgi 數目
spawn-fcgi 已經成為獨立套件,在 Debian 中可以透過 apt 來安裝。# sudo apt-get install spawn-fcgi
丟個 script 到 /etc/init.d/ 目錄下,讓 php-fcgi 開機時就能自己啟動。
# vim /etc/init.d/php-fastcgi
# chmod +x php-fastcgi
# update-rc.d -f php-fastcgi defaults 2
內容如下:
#!/bin/bash
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 1
# Short-Description: Run the PHP FastCGI
# Description: PHP FastCGI environment for Nginx web server
#
### END INIT INFO
CHILDREN=1
PHP5=/usr/bin/php5-cgi
SOCKET=/tmp/php-cgi.socket
PIDFILE=/var/run/php-cgi.pid
USER=www-data
GROUP=www-data
SPAWN=/usr/bin/spawn-fcgi
OPT="-s $SOCKET -P $PIDFILE -f $PHP5 \
-u $USER -g $GROUP -C $CHILDREN"
do_start() {
start-stop-daemon --start --quiet --exec $SPAWN -- $OPT
}
do_stop() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
}
do_restart() {
start-stop-daemon --stop --quiet --pidfile $PIDFILE
sleep 1
start-stop-daemon --start --quiet --exec $SPAWN -- $OPT
}
case "$1" in
start)
do_start;;
stop)
do_stop;;
restart)
do_restart;;
*)
echo "Usage: php-fastcgi {start|stop|restart}" ;;
esac
沒有留言:
張貼留言