当前位置: 首页 > 图文教程 > 服务器 > Linux服务器 > Ubuntu8.04快速搭建nginx+php系统

Linux服务器
在Apache环境下成功的运行ASP.NET
NoMachine,NX远程遥控的新典范
用gnump3d架设流体服务器
LinuxNFS(网络文件系统)服务器性能优化
Linux中建立安全的ProFTPD应用经验谈
手把手教你配Liunx流媒体服务器(上)
Linux系统中搭建LAMP动态博客网站
实例教你在Linux下建立代理服务器
简单架设Jabber局域网即时通讯服务器
ldap大容量邮件系统数据库应用指南
超全的NFSserver教程手册
用slackware架设虚拟主机管理系统(一)
用slackware架设虚拟主机管理系统(二)
slackware10.1下架设apache+tomcat+jk实例
SFTPD服务器架设菜鸟手记
手把手教你wuftp服务器的配置
使用TSIG和DNSSEC加固域名服务器
Linux上构建一个RADIUS服务器详解(1)
用CoyoteLinux制作好的打印服务器
routeros常用命令详解

Linux服务器 中的 Ubuntu8.04快速搭建nginx+php系统


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-18   浏览: 110 ::
收藏到网摘: n/a

昨天在FreeBSD下玩了nginx+php,今天到ubuntu下来玩玩了,首先要感谢“过够了”的文章以下是按他的文章修改而来。在ubuntu下搭建比freebsd下速度要快得多,因为在freebsd我是用ports方式安装,需要编译,ubuntu下直接apt-getinstall的方式安装,速度很快,下面就来开始安装吧!

1,安装nginx,执行以下命令,很快完成,不过目前apg-get方式安装默认是0.5.33的版本

sudoapt-getinstallnginx

配置文件默认安装位置:

conf:/etc/nginx/nginx.conf
bin:/usr/sbin/nginx
vhost:/etc/nginx/sites-enable/default
cgi-params:/etc/nginx/fastcgi-params

例:建一个虚拟Server

server{
listen80;
server_namewww.23day.com;
access_log/var/log/nginx/home.ucenter.access.log;

location/{
root/var/www/23day.com;
indexindex.php;

location~\.php${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/var/www/23day.com$fastcgi_script_name;
include/etc/nginx/fastcgi_params;
}
}

2,安装php-cgi模块

执行sudoapt-getinstallphp5-cgi

配置文件默认安装位置:

php-cgi:/usr/bin/php-cgi
php5-cgi:/usr/bin/php5-cgi
cgiconfig:/usr/bin/cgi/php.ini

修改php.ini文件的cgi.fix_pathinfo数据为1,默认为0cgi.fix_pathinfo=1;这样php-cgi方能正常使用SCRIPT_FILENAME这个变量

3,安装spawn-fcgispawn-fcgi是lighttpd的一个用来控制php-cgi的工具.

如果系统没有安装GCC编译环境,刚需要在安装lighttpd之前要安装build-essential工具包,执行以下命令

sudoapt-getinstallbuild-essential
wgethttp://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz
tar-xvflighttpd-1.4.19.tar.gz
cdlighttpd-1.4.19/
sudoapt-getinstalllibpcre3-dev
./configure–without-zlib–without-bzip2
make
sudocpsrc/spawn-fcgi/usr/local/bin/spawn-fcgi

这样cgi控制器就安装完成.

4.启动测试系统.启动fast_cgi:

spawn-fcgi-a127.0.0.1-p9000-C5-uwww-data-gwww-data-f/usr/bin/php-cgi

注意:ip,端口与nginx服务器中的cgi-pass要对应.-C表示打开几个cgi进程

启动nginx

sudo/etc/init.d/nginxstart

好了,如果没有出错信息,则说明配置成功了,现在写个phpinfo测试下吧!

最后,附上我的/etc/nginx/sites-enable/default的配置文件,此配置文件启用了rewrite功能

server{
listen80;
server_namelocalhost;

access_log/var/log/nginx/localhost.access.log;

location/{
root/var/www/nginx-default;
indexindex.php;

if(-f$request_filename/index.html){
rewrite(.*)$1/index.htmlbreak;
}
if(-f$request_filename/index.php){
rewrite(.*)$1/index.php;
}
if(!-f$request_filename){
rewrite(.*)/index.php;
}

}

#error_page404/404.html;

#redirectservererrorpagestothestaticpage/50x.html
#
error_page500502503504/50x.html;
location=/50x.html{
root/var/www/nginx-default;
}

#proxythePHPscriptstoApachelisteningon127.0.0.1:80
#
#location~\.php${
#proxy_passhttp://127.0.0.1;
#}

#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
#
location~\.php${
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME/var/www/nginx-default$fastcgi_script_name;
include/etc/nginx/fastcgi_params;
}

#denyaccessto.htaccessfiles,ifApache’sdocumentroot
#concurswithnginx’sone
#
#location~/\.ht{
#denyall;
#}
}

#anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration
#
#server{
#listen8000;
#listensomename:8080;
#server_namesomenamealiasanother.alias;

#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}

#HTTPSserver
#
#server{
#listen443;
#server_namelocalhost;

#sslon;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;

#ssl_session_timeout5m;

#ssl_protocolsSSLv2SSLv3TLSv1;
#ssl_ciphersALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_cipherson;

#location/{
#roothtml;
#indexindex.htmlindex.htm;
#}
#}

上一页[1][2]