顯示具有 apache 標籤的文章。 顯示所有文章
顯示具有 apache 標籤的文章。 顯示所有文章

1/05/2007

[整理] Windows 上面跑 Apache 2.2 + Mongrel

Windows 上面 Ruby 效能不佳,所以我曾經建議不使用 Windows 作為 Service 環境。但是如果你真的要用 Windows 作為 Server ,你可以看這一篇。

不過請注意,我在之前就講過,我沒有 Windows 可以測試,只能整理別人的文章。尤其參考最多的是 Robbin 寫的 在Windows平台使用Apache2.2和Mongrel运行Ruby on Rails,雖然沒有照著翻譯,但是你依舊可以視這篇文章為 Robbin 本文的繁體中文整理翻譯版,榮耀是歸於 Robbin 的。

安裝 Ruby on Rails and Mongrel
下載Windows版的Ruby來安裝,安裝時請記得裝 RubyGems。再來請用 gem 安裝下列三個套件
gem i rails mongrel mongrel_service –y
啟動 mongrel_service
mongrel_service 就是 Windows 上面 Win32 Service 的 plugin。我們要先將 Mongrel 登記為其中一個 Windows Service。
mongrel_rails service::install -N service_name -c c:\rails\service -p 3000 –e production
  • -N :win32 service 名字
  • -c:Rails 程式 root 目錄
  • -p:聽的 port
  • -e:Rails 環境
仔細去看Win32 的service list,你會發現出現了一個你剛剛登記的 service_name。啟動的話就是
mongrel_rails service::start -N service_name
停止就是
mongrel_rails service::stop -N service_name
取消 service 登記就是
mongrel_rails service::remove -N service_name
如果你想 Windows 啟動,自動啟動 Mongrel Service,請按下
sc config service_name start= auto
如果你想說順便一起啟動 Mongrel Service 跟 MySQL,請按下
sc config service_name start= auto dependency= MySql

Mongrel_cluster ?
大家一定很懷念 Mongrel Cluster 這樣的神兵利器吧,很可惜,Windows 上面沒有 Mongrel Cluster,所以大家要啟動 3000 ~ 3009 就得這樣搞
mongrel_rails service::install -N service_name1 -p 3000 –e production
mongrel_rails service::install -N service_name2 -p 3001 –e production
mongrel_rails service::install -N service_name3 -p 3002 –e production
...
mongrel_rails service::install -N service_name4 -p 3009 –e production
笨嗎?蠢嗎?所以才跟你說 Ruby on Rails 不適合用 Windows 咩。
安裝 Apache 2.2
去 Apache 網站下載 Apache 2.2 Windows 版本。然後在httpd.conf enable module
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
使用 config file 就如同我這個網頁寫的方式,或是直接看 Robbin 寫的也可以。


延伸閱讀


12/14/2006

Apache 2.2 + Mongrel 設定方式

本來沒有打算寫的,不過看到 RailsCN 似乎有人有問題,所以還是順便寫一下好了。架設一些觀念在此我有作介紹,可以參考一下。


設定 Mongrel Cluster

請將你的 Mongrel Cluster 設定好,這裡預設 port 從 4000 ~ 4009 ,一共十個,跑在 production 環境下
mongrel_rails cluster::configure -e production -p 4000 -N 10
mongrel_rails cluster::start
修改 Apache 2.2 設定檔

Apache 的設定檔放在 httpd.conf ,以下修改內容皆在 httpd.conf 裡面設定。

首先確定你的 Apach 2.2 有 enable apache 的其中一個 Module mod_proxy
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
再來我們開始設定 Mongrel Cluster 的 reverse proxy 設定,首先我們給這組 cluster 取名叫做 examplecluster,他是10組 Mongrel ,跑在 port 4000 ~ 4009 之中
<proxy balancer://examplecluster>
# cluster member 1
BalancerMember http://127.0.0.1:4000
BalancerMember http://127.0.0.1:4001
....
BalancerMember http://127.0.0.1:4009
</proxy>
再來假設你的 hostname 為 example.com,我們開始設定 virtual host
<virtualhost example.com:80>
ServerName example.com
ServerAdmin root@example.com
DocumentRoot "/var/www/example.com/htdocs"
ProxyPass /images !
ProxyPass /stylesheets !
ProxyPass /javascripts !
ProxyPass / balancer://examplecluster/
ProxyPassReverse / balancer://examplecluster/
</virtualhost>

重點是在於 ProxyPass,ProxyPass 代表 images,stylesheets,javascript 等 static file 交給 Apache 處理,不要給 Mongrel 處理。 還有 ProxyPassReverse 要指定正確的 cluster name ,我們要指定為 examplecluster。

最後重起 Apache 即可。本設定改自著名的文章 Scaling Rails with Apache 2.2, mod_proxy_balancer and Mongrel,還有 Robin 的 在Windows平台使用Apache2.2和Mongrel运行Ruby on Rails。設定是在 Gentoo Linux + Apache 2.2.3 + Mongrel 跑完全沒有任何問題。