主題: lighttpd on FreeBSD with Lifetype 作者: ericj 於 四月 21, 2006, 09:18:01 下午 這裡以FreeBSD的ports安裝為例,其他OS應該也是差不多,
lighttpd目前似乎沒有windows的版本。 1.安裝 www/php5-cgi 或者 www/php4-cgi,我是安裝php5-cgi,底下是我的 make config 選項 程式碼: [X] REDIRECT Enable force-cgi-redirect support 2.安裝www/lighttpd 我的選項是[X] DISCARD Enable discard-path support [X] FASTCGI Enable fastcgi support [X] PATHINFO Enable path-info-check support [X] MULTIBYTE Enable zend multibyte support 程式碼: [X] MYSQL Enable MYSQL support 3 安裝 lang/php5-extensions[X] CML Enable Cache Meta Language support 把一些會用到的 php module 安裝進去 如果不要用的話,再到 /usr/local/etc/php/extensions.ini 把不要用的註解掉就好了。(載入越多module你的php就會越耗記憶體) 4. lighttpd 比較特殊的是 它需要用 phpx-cgi 而不是一般apache使用的 mod_php 所以我是把 apache2 移除 , mod_php 移除 , phpX-*extensons 移除通通重裝。 在 FreeBSD 下面,可以移除 mod_phpX ,裝 php5-cgi 後, 再用 php5-extensions 來重新安裝extenstions 5.再來是 lighttpd 設定的部份 "/usr/local/etc/lighttpd.conf" 我 enable 的 module 有 程式碼: "mod_rewrite", "mod_alias", "mod_access", "mod_fastcgi", "mod_rrdtool", "mod_accesslog" 程式碼: server.document-root = "/home/plog/" ##請改成你的lifetype位置 server.errorlog = "/var/log/lighttpd.error.log" ##請自行 touch一個,再chown www:www index-file.names = ( "summary.php", "index.php", "index.html", "index.htm", "default.htm" ) accesslog.filename = "/var/log/lighttpd.access.log" #跟errorlog一樣,請自行touch一個再chown 程式碼: ## 這是因為 /home/plog/tmp 是不可以被讀取的,等同於之前在 /home/plog/tmp下的.htaccess的 $HTTP["url"] =~ "/tmp" { url.access-deny = ( "" ) } 程式碼: fastcgi.map-extensions = ( "/album" => ".php", "/post" => ".php", "/archives" => ".php", "/static" => ".php", "/rss" => ".php", "/category" => ".php", "/trackbacks" => ".php", "/comment" => ".php", "/resource" => ".php", "/get" => ".php", "/blog" => ".php", "/user" => ".php" ) ## 這些是因為 /home/plog下有些檔案,要用php的方式去處理,而不是下載回來,要設定不然,像是相簿、資料夾就無法使用 程式碼: fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/tmp/php-fastcgi.socket", "bin-path" => "/usr/local/bin/php", "bin-environment" => ( "PHP_FCGI_CHILDREN" => "5", "PHP_FCGI_MAX_REQUESTS" => "1000" ), "bin-copy-environment" => ( "PATH", "SHELL", "USER" ), "broken-scriptfilename" => "enable" ) ) ) ##這些是我目前 php-fastcgi的設定,跟你server的負荷能力有關 程式碼: url.rewrite= ( "^([0-9]+)_[^/]+/archive/([0-9]{6}).html$" => "index.php?blogId=$1&Date=$2", "^([0-9]+)_[^/]+/albums/([0-9]+)_[^.]+.html$" => "index.php?op=ViewAlbum&blogId=$1&albumId=$2", "^([0-9]+)_[^/]+/albums/$" => " index.php?op=ViewAlbum&blogId=$1&albumId=0", "^([0-9]+)_[^/]+/categories/([0-9]+)_[^.]+.html$" => "index.php?blogId=$1&postCategoryId=$2", "^([0-9]+)_[^/]+/feeds/categories/([0-9]+)_[^.]+/(.*)$" => "rss.php?blogId=$1&categoryId=$2&profile=$3", "^([0-9]+)_[^/]+/feeds/(.*)$" => "rss.php?blogId=$1&profile=$2", "^([0-9]+)_[^/]+/trackbacks/([0-9]+)_[^.]+.html$" => "index.php?op=Trackbacks&blogId=$1&articleId=$2", "^([0-9]+)_[^/]+/comment/([0-9]+)_[^.]+.html$" => "index.php?op=Comment&blogId=$1&articleId=$2", "^([0-9]+)_[^/]+/resources/([^.]+).([^.]+).html$" => "index.php?op=ViewResource&blogId=$1&resource=$2.$3", "^([0-9]+)_[^/]+/(.+)$" => "index.php?op=Template&blogId=$1&show=$2", "^([0-9]+)(_[^/]+)?$" => "index.php?blogId=$1", "^([0-9]+)_[^/]+/archive/([0-9]{8}).html$" => "index.php?blogId=$1&Date=$2", "^([0-9]+)_[^/]+/get/(.+)$" => "resserver.php?blogId=$1&resource=$2") ##這些是我的url-rewrite規則,目前看起來沒什麼問題,我過因為我使用的是自訂網址,不確定一般網址會怎樣 其實 lighttpd 的設定檔很人性化,一下子就懂了,re-write rule也是。 比對一下 /home/plog/下的 .htaccess 再改過來 lighttpd 的格式就好了 他的特色是對於 static page的處理超強,有支援串流格式 (flv),省資源。 在Linux下當web server效能很棒。試試看吧! 大概要注意的就是 phpX-cgi , lighttpd 的re-write rule, php-fastcgi在lighttpd 下的設定 當 lighttpd cache起來的時候,速度超快的! 主題: Re: lighttpd on FreeBSD with Lifetype 作者: markwu 於 四月 22, 2006, 01:20:01 上午 這是一篇很棒的文章!
其實可以再加上 eaccelerator 與 zend optimizer 的 support,讓 web server 可以執行 php 的 opcode,而非每次 request 都要重新 compile 一次。 這樣可以加大你 server 的負載能力。 至於你說的: 引用 這些是我目前 php-fastcgi的設定,跟你server的負荷能力有關 的確是這樣。最好的方式就是先試 run 幾次,然後用 ab 或 ab2 做一下壓力測試,並且估一下你的平均 request 所使用的 memory 數量,然後由此回推他的最高的max concurrent reuqest 數目。 例如平均的 request memory 用量是 10m,然後你有 1 G 的記憶體,開機後只剩 800M,那麼 max concurrent reuqest 最好不要超過 80。當然,這是很保守的算法,這還是跟你的機器有很大的關係。 太大,會造成一直使用 swap memory,速度越來越慢,最後死機給你看。 **BTW,我直接把這篇先置頂了!謝謝你的分享! Mark 主題: Re: lighttpd on FreeBSD with Lifetype 作者: Augu 於 十二月 19, 2006, 09:24:40 下午 lighttpd 的 windows 版本 Kevin Worthington 有 porting。
http://www.kevinworthington.com:8181/index.php/category/computers/lighttpd/ 主題: Re: lighttpd on FreeBSD with Lifetype 作者: alex867 於 一月 16, 2007, 11:33:52 上午 請問一下
我已經改用lighttpd來當我的server 但是發現像是http://aaa.bbb.ccc/blog/5 會找不到 但是http://aaa.bbb.ccc/blog/5/ 就可以(末端多個斜線) 這個是哪裡要設定呀? 主題: Re: lighttpd on FreeBSD with Lifetype 作者: lss 於 一月 16, 2007, 02:28:43 下午 lighttpd 的 .htaccess 寫法不一樣(好像連檔名也不太一樣的樣子),請參考官方網站的文件修改以讓 .htaccess 的設定能生效。
lss 主題: Re: lighttpd on FreeBSD with Lifetype 作者: hollowaysxp 於 五月 22, 2007, 09:29:03 下午 我是羽毛2.0的用戶。
我用FreeBSD6.2,沒想到FreeBSD 6.2還有提供lighthttpd。 我好像從以前Win32開始都是玩羽毛和IIS。 其它的httpd還滿少碰的。 |