在Windows平臺使用LightTPD和Mongrel運行Ruby on Rails

什麼是Mongrel?

一個快速的Web Server,速度快於WEBrick甚多,網絡上的介紹很多。

什麼是Lighttpd?

用於轉發request到a cluster of Mongrel,網絡上的介紹同樣很多。

使用它們可以解決Rails在request上面出現的問題。

一、首先從rubyforge網站下載One-Click Ruby Install,運行安裝程序,就安裝好了ruby和rubygems。
運行命令:
gem install rails –y
gem install mongrel –y
gem install mongrel_service -y
安裝好了rails和mongrel,注意安裝mongrel和montrel_service時選擇for windows。

二、把Mongrel作爲Services啓動
mongrel_rails service::install -N depot -c d:\Rubyproject\depot -p 3000 –e production
-N指明服務名稱,-c指明rails應用的目錄,-p是mongrel監聽的tcp端口,-e是啓動模式爲生產模式

這樣打開控制面版|管理工具|服務,就可以發現增加了一項名爲“depot”的服務,就可以通過控制面版來管理服務了。如果需要命令行啓動和關閉該服務,那麼:
mongrel_rails service::start -N depot
mongrel_rails service::stop -N depot
如果需要從服務中註銷該項服務,那麼:
mongrel_rails service::remove -N depot
如果需要安裝多個mongrel實例,那麼可以這樣:
mongrel_rails service::install -N depot0 -c d:\Rubyproject\depot -p 3000 –e production
mongrel_rails service::install -N depot1 -c d:\Rubyproject\depot -p 3001 –e production
諸如此類。

三、安裝和配置LightTPD
首先下載lighttpd for windows,這個地址是我從網絡找到的http://blog.621000.net/download.php?id=627,還有一個WLMP包,這一個整合包,方便普通用戶,
包括以下軟件:
LightTPD 1.4.15
MySQL 5.0.44
PHP 5.2.3
MiniPerl 5.8.8
OpenSSL 0.9.8e
phpMyAdmin 2.10.2

windows版本的lighttpd默認被安裝在c:/lighttpd,這個安裝位置是不能修改的

配置Lighttpd,配置port:

打開c:\lighttpd\conf\lighttpd-inc.conf

取消 server.port = 81 前的註釋,你也可以使用port:80

開啓模塊,其他模塊不要亂開,會出問題

server.modules = ("mod_proxy",
"mod_rewrite",
"mod_accesslog",
"mod_alias" )

另外在這個配置文件末位加上:

proxy.debug = 0
proxy.balance = "fair"
proxy.server = ( "/" =>
(
( "host" => "127.0.0.1", "port" => 3000)
)
)

這裏的port就是Mongrel server的port,啓動Lighttpd使用命令:

c:\lighttpd\lighttpd.exe -f conf\lighttpd-inc.conf -m lib

也可以直接運行c:\lighttpd\Start-LightTPD.bat

通過http://localhost:81/depot 或http://(服務器的IP地址或完整的計算機名稱):81/depot就可以成功訪問
使用計算機名時,要在C:\WINDOWS\system32\drivers\etc\hosts文件中增加: 服務器IP地址 服務器計算機名稱,如:192.168.0.1 depot
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章