IT猫扑网:您身边最放心的安全下载站! 最新更新| 软件分类| 专题汇总| 手机版

您当前所在位置:IT猫扑网 > 服务器 > 其他服务器 > Ubuntu/Debian下简易Nginx+FastCGI+PHP配置

Ubuntu/Debian下简易Nginx+FastCGI+PHP配置

时间:2015-06-28 00:00 来源:IT猫扑网|http://www.itmop.com/ 作者:网管联盟 我要评论(0)

由于目前Nginx还不支持直接运行PHP,但是Nginx支持FastCGI,可以用FastCGI模式运行PHP作为后端。Nginx不能像Lighttpd那样自动启动FastCGI,所以这里要借一下lighttpd的spawn-fcgi工具来启动PHP。

安装PHP

以下为引用的内容:

sudo apt-get install php5 php5-cgi

获得spawn-fcgi

下载lighttpd,解压,

以下为引用的内容:

./configure
make
sudo cp ./src/spawn-fcgi /usr/local/sbin/

 

spawn-fcgi启动脚本

以下为引用的内容:

#!/bin/sh

# /etc/init.d/php-fastcgi: start php fastcgi

set -e
. /lib/lsb/init-functions

BINPATH=&/usr/bin/spawn-fcgi&

CGIPATH=&/usr/bin/php-cgi&
ADDR=&127.0.0.1″
PORT=&9000″
CHILDS=&2″
RUNUSER=&www-data&
RUNGROUP=&www-data&
PIDFILE=&/var/run/phpcgi.pid&

OPTS=&-f $CGIPATH -a $ADDR -p $PORT -C $CHILDS -P $PIDFILE -u $RUNUSER -g $RUNGROUP&

do_start() {
start-stop-daemon –start –quiet
–pidfile $PIDFILE
–exec $BINPATH — $OPTS || return 1
return 0
}

do_stop() {
start-stop-daemon –stop –quiet –oknodo
–pidfile $PIDFILE || return 1
return 0
}

case &$1″ in
start)
log_begin_msg &Starting PHP FastCGI …&
do_start || log_end_msg 1
log_end_msg 0
;;
stop)
log_begin_msg &Stopping PHP FastCGI …&
do_stop || log_end_msg 1
log_end_msg 0
;;
reload|force-reload)
log_begin_msg &Reloading … Do nothing&
log_end_msg 0
;;
restart)
log_begin_msg &Restarting PHP FastCGI …&
do_stop
sleep 5
do_start || log_end_msg 1
log_end_msg 0
;;
*)
log_success_msg &Usage: /etc/init.d/php-fastcgi  {start|stop|reload|force-reload|restart}&
exit 1
esac

exit 0

脚本保存到 /etc/init.d/php-fastcgi,然后添加到启动项中:

update-rc.d php-fastcgi start 89 2 3 4 5 。 stop 19 0 1 6 。

nginx的设置

修改站点的设置,使php传到后端处理

以下为引用的内容:

location ~ .php$
fastcgi_pass   127.0.0.1:9000;
fastcgi_index  index.php;
fastcgi_param  SCRIPT_FILENAME /path/to/your/site$fastcgi_script_name;
include  fastcgi_params;
}

关键词标签:Ubuntu,Debian,Nginx

相关阅读 使用Python配平化学方程式的方法 CentOS NTP服务器安装与配置 Windows Server服务器日常管理技巧 RedHat Linux DHCP服务器中继 明明白白你的Linux服务器——安全篇 linux服务器基本安全配置手册

文章评论
发表评论

热门文章 CentOS NTP服务器安装与配置 CentOS NTP服务器安装与配置 nginx搭建flv流媒体服务器 nginx搭建flv流媒体服务器 CentOS 5.4+OpenVZ+Vtonf自建VPS服务器 CentOS 5.4+OpenVZ+Vtonf自建VPS服务器 DHCP服务器数据库移植的三个步骤 DHCP服务器数据库移植的三个步骤 备份还原DHCP服务器配置的具体操作 备份还原DHCP服务器配置的具体操作 Windows 2003下配置架设NTP时间服务器 Windows 2003下配置架设NTP时间服务器

相关下载

人气排行 VMware中Shared Folders(共享文件夹)的配置 CentOS NTP服务器安装与配置 nginx搭建flv流媒体服务器 Windows 2003下配置架设NTP时间服务器 详细!解决WSUS服务器更新问题(附官方链接) heartbeat+LVS-ipvsadm+ldirectord搭建lvs DR集群 nginx的自动启动脚本 使用Python配平化学方程式的方法 linux服务器基本安全配置手册 DHCP服务器的授权问题 Ubuntu/Debian下简易Nginx+FastCGI+PHP配置 在Debian Linux系统下搭建DHCP服务器