昨天在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;
#}
#} 本文出自:億恩科技【www.23lll.com】
服務器租用/服務器托管中國五強!虛擬主機域名注冊頂級提供商!15年品質保障!--億恩科技[ENKJ.COM]
|