php – nginx 502坏网关 – fastcgi不听? (Debian 5)
我有使用nginx的经验,但它总是为我预先安装(通过VPS.net预先配置的图像).我真的很喜欢它为我做的,现在我正在尝试使用apt-get在我自己的服务器上安装它.这是一个相当新鲜的Debian 5安装.我没有安装额外的软件包,但它们都是.deb的,没有手动编译或任何疯狂的事情.
Apache已经安装但我禁用了它.我做了apt-get install nginx并且运行正常.根据我的需要稍微改变了配置,尽管即使使用默认配置也会出现同样的问题. 我花了一段时间才发现nginx的默认debian包不会自动生成fastcgi进程.这是非常蹩脚的,但我想出了如何使用这个脚本,我发现在许多不同的网站上发布: #!/bin/bash ## ABSOLUTE path to the PHP binary PHPFCGI="/usr/bin/php5-cgi" ## tcp-port to bind on FCGIPORT="9000" ## IP to bind on FCGIADDR="127.0.0.1" ## number of PHP children to spawn PHP_FCGI_CHILDREN=10 ## number of request before php-process will be restarted PHP_FCGI_MAX_REQUESTS=1000 # allowed environment variables sperated by spaces ALLOWED_ENV="ORACLE_HOME PATH USER" ## if this script is run as root switch to the following user USERID=www-data ################## no config below this line if test x$PHP_FCGI_CHILDREN = x; then PHP_FCGI_CHILDREN=5 fi ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_CHILDREN" ALLOWED_ENV="$ALLOWED_ENV PHP_FCGI_MAX_REQUESTS" ALLOWED_ENV="$ALLOWED_ENV FCGI_WEB_SERVER_ADDRS" if test x$UID = x0; then EX="/bin/su -m -c "$PHPFCGI -q -b $FCGIADDR:$FCGIPORT" $USERID" else EX="$PHPFCGI -b $FCGIADDR:$FCGIPORT" fi echo $EX # copy the allowed environment variables E= for i in $ALLOWED_ENV; do E="$E $i=${!i}" done # clean environment and set up a new one nohup env - $E sh -c "$EX" &> /dev/null & 当我做“ps -A | grep php5-cgi”时,我看到10个进程正在运行,应该准备好听. 但是当我尝试通过nginx查看网页时,我只得到502错误的网关错误. 经过一段时间的考虑,我尝试telnet到127.0.0.1 9000(fastcgi正在侦听端口9000,并且nginx配置为与该端口通信),但它只是立即关闭连接. 这让我觉得问题在于fastcgi,但我不确定我能做些什么来测试它.它可能只是关闭连接,因为它没有得到任何数据进行处理,但它立即关闭,所以这让我思考. 那么……有什么建议吗?我无法弄明白.凌晨1点就没有用,但我在这里疯了!
在我的服务器上我也使用nginx fcgi.
我的解决方案并非万无一失,但至少可行.我有这个脚本在/etc/init.d/下使用spawn-fcgi和php5-cgi #!/bin/bash PHP_SCRIPT='/usr/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www-data -f /usr/bin/php5-cgi' 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: php-fastcgi {start|stop|restart}" exit 1 ;; esac exit $RETVAL 和相关的nginx conf是这样的: server { location ~ .php${ fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include /etc/nginx/fastcgi.conf; fastcgi_param SCRIPT_FILENAME /var/www/hyperblasted/$fastcgi_script_name; } ... } 并且fastcgi.conf包含以下内容 fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; 希望这可以帮助 :) PS:有了这个设置,我遇到了cgi守护进程不时会死的问题.我通过每5分钟在一个cronjob中执行此操作解决了这个问题: if ps aux | grep 'php5-cgi' | grep -v grep > /dev/null ; then echo "PHP-cgi is runnning !" else echo "PHP-cgi is down. Starting over..." /etc/init.d/php-fcgi start fi (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |