Freebsd Nginx + fastgci

Nginx
==================================
cd /usr/ports/www/nginx-devel
make install clean

[X] HTTP_MODULE
[X] HTTP_PERL_MODULE
[X] HTTP_REWRITE_MODULE
[X] HTTP_STATUS_MODULE

======================================

php
==========================================
cd /usr/ports/lang/php5
make install clean

[X] CLI Build CLI version
[X] CGI Build CGI version
[X] REDIRECT Enable force-cgi-redirect support (CGI only)
[X] DISCARD Enable discard-path support (CGI only)
[X] FASTCGI Enable fastcgi support (CGI only)
[X] PATHINFO Enable path-info-check support (CGI only)
=============================================================

spawn-fcgi
===============================================================
pkg_add -r -v lighttpd

cp /usr/local/bin/spawn-fcgi /root/
pkg_delete -v lighttpd-1.4.xxx
cp /root/spawn-fcgi /usr/local/bin/spawn-fcgi
===================================================================

Test
=====================================================================
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u www -g www -f /usr/local/bin/php-cgi

sockstat -4 | grep 9000
========================================================================================

Скрипт запуска

/usr/local/etc/rc.d/php.cgi.sh
=========================================================
#!/bin/sh
# NGINX FastCGI php5 startup shell script
# Feedback <vivek@nixcraft.com>
# http://bash.cyberciti.biz/web-server/fastcgi-php-server-start-stop-script/
# Set ME #
PROVIDES=php-cgi
LIGHTTPD_FCGI=/usr/local/bin/spawn-fcgi
SERVER_IP=127.0.0.1
SERVER_PORT=9000
SERVER_USER=www
SERVER_GROUP=www
PHP_CGI=/usr/local/bin/php-cgi
PGREP=/bin/pgrep
KILLALL=/usr/bin/killall
### No editing below ####
cmd=$1

pcgi_start(){
echo "Starting $PROVIDES..."
$LIGHTTPD_FCGI -a $SERVER_IP -p $SERVER_PORT -u $SERVER_USER -g $SERVER_GROUP -f $PHP_CGI
}

pcgi_stop(){
echo "Killing $PROVIDES..."
$KILLALL $PROVIDES
}

pcgi_restart(){
pcgi_stop
pcgi_start
}

pcgi_status(){
$PGREP $PROVIDES > /dev/null
[ $? -eq 0 ] && echo "$PROVIDES running" || echo "$PROVIDES NOT running"

}

pcgi_help(){
echo "Usage: $0 {start|stop|restart|status}"
}

case ${cmd} in
[Ss][Tt][Aa][Rr][Tt]) pcgi_start;;
[Ss][Tt][Oo][Pp]) pcgi_stop;;
[Rr][Ee][Ss][Tt][Aa][Rr][Tt]) pcgi_restart;;
[Ss][Tt][Aa][Tt][Uu][Ss]) pcgi_status ;;
*) pcgi_help ;;
esac
===============================================================================
chmod +x /usr/local/etc/rc.d/php.cgi.sh

/usr/local/etc/rc.d/php.cgi.sh start
sockstat -4 | less
===============================================================================
/usr/local/etc/rc.d/php.cgi.sh stop

=================================================

Настариваем nginx
/usr/local/etc/nginx/nginx.conf
=========================================================================

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /websites/example.com/http$fastcgi_script_name;
include fastcgi_params;
}

================================================================================================

/etc/rc.conf
=============================
nginx_enable="YES"
==============================================
nginx -c /usr/local/etc/nginx/nginx.conf -t
/usr/local/etc/rc.d/nginx restart
====================================================

Ну и посмотрим что в итоге
ee /usr/local/www/nginx/index.php
=========================================
<? phpinfo(); ?>
====================================

Добавить комментарий

Ваш e-mail не будет опубликован. Обязательные поля помечены *