无法在 nginx 中启动 php

无法在 nginx 中启动 php

我想启动 php+nginx。
我安装了 nginx 和 php 以及 FastCGI。现在我配置它: /etc/nginx/sites-enabled/default

server {
server_name localhost;
root /srv/www/localhost/public_html;


location ~ \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME /srv/www/localhost/public_html$fastcgi_script_name;
}
}

/usr/bin/php-fastcgi

/bin/bash #!/bin/bash

FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
ADDRESS=127.0.0.1
PORT=9000
PIDFILE=/var/run/php-fastcgi/php-fastcgi.pid
CHILDREN=6
PHP5=/usr/bin/php5-cgi

/usr/bin/spawn-fcgi -a $ADDRESS -p $PORT -P $PIDFILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -f $PHP5

使其可执行:

chmod +x /usr/bin/php-fastcgi

/etc/init.d/php-fastcgi

#!/bin/bash

PHP_SCRIPT=/usr/bin/php-fastcgi
FASTCGI_USER=www-data
FASTCGI_GROUP=www-data
PID_DIR=/var/run/php-fastcgi
PID_FILE=/var/run/php-fastcgi/php-fastcgi.pid
RET_VAL=0

case "$1" in
    start)
      if [[ ! -d $PID_DIR ]]
      then
        mkdir $PID_DIR
        chown $FASTCGI_USER:$FASTCGI_GROUP $PID_DIR
        chmod 0770 $PID_DIR
      fi
      if [[ -r $PID_FILE ]]
      then
        echo "php-fastcgi already running with PID `cat $PID_FILE`"
        RET_VAL=1
      else
        $PHP_SCRIPT
        RET_VAL=$?
      fi
  ;;
    stop)
      if [[ -r $PID_FILE ]]
      then
        kill `cat $PID_FILE`
        rm $PID_FILE
        RET_VAL=$?
      else
        echo "Could not find PID file $PID_FILE"
        RET_VAL=1
      fi
  ;;
    restart)
      if [[ -r $PID_FILE ]]
      then
        kill `cat $PID_FILE`
        rm $PID_FILE
        RET_VAL=$?
      else
        echo "Could not find PID file $PID_FILE"
      fi
      $PHP_SCRIPT
      RET_VAL=$?
  ;;
    status)
      if [[ -r $PID_FILE ]]
      then
        echo "php-fastcgi running with PID `cat $PID_FILE`"
        RET_VAL=$?
      else
        echo "Could not find PID file $PID_FILE, php-fastcgi does not appear to be running"
      fi
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart|status}"
      RET_VAL=1
  ;;
esac
exit $RET_VAL

使其可执行chmod +x /etc/init.d/php-fastcgi。创建文件/srv/www/localhost/public_html/index.php
启动服务:

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

然后 go127.0.0.1/index.php但得到502 Bad Geteway。在 nginx error.log 中:

2013/07/09 14:14:25 [error] 3260#0: *3 connect() filed(111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: localhost, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "127.0.0.1"

什么地方可能出错了?

答案1

不确定。cgi 是否已启动(ps aux 搜索 php cgi)?php-cgi 是否已安装?

最重要的是,你为什么不使用 php5-fpm 包?我认为这是将 php 和 nginx 结合在一起的推荐方式,你不需要使用额外的脚本,只需 /etc/init.d/php5-fpm start

相关内容