在Windows平台使用Apache2.2和Mongrel運行Ruby on Rails

來源:互聯網
上載者:User
一、安裝Ruby、rails、mongrel和Apache2.2 從rubyforge網站下載One-Click Ruby Install,運行安裝程式,就安裝好了ruby和rubygems。 運行命令:gem install rails –ygem install mongrel –ygem install mongrel_service -y安裝好了rails和mongrel 從Apache網站下載Windows版本的Apache2.2,運行安裝程式,就安裝好了Apache2.2。 二、把Mongrel作為Services啟動 mongrel_rails service::install -N depot -c d:/Rubyproject/depot -p 3000 –e production-N指明服務名稱,-d指明rails應用的目錄,-p是mongrel監聽的tcp連接埠,-e是啟動模式為生產模式 這樣開啟控制面版|管理工具|服務,就可以發現增加了一項名為“depot”的服務,就可以通過控制面版來管理服務了。如果需要命令列啟動和關閉該服務,那麼:mongrel_rails service::start -N depotmongrel_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 productionmongrel_rails service::install -N depot1 -c d:/Rubyproject/depot -p 3001 –e production諸如此類。 三、配置Apache2.2 用編輯工具開啟Apache2.2目錄下面的conf/httpd.conf,需要取消如下模組的注釋:LoadModule proxy_module modules/mod_proxy.soLoadModule proxy_balancer_module modules/mod_proxy_balancer.soLoadModule proxy_http_module modules/mod_proxy_http.so如果你希望對頁面輸出使用壓縮,也需要取消如下模組的注釋:LoadModule deflate_module modules/mod_deflate.so 然後按如下內容配置基於HTTP代理的負載平衡:

xml 代碼 
  1. ProxyRequests Off   
  2. <Proxy balancer://myCluster>  
  3.   BalancerMember http://localhost:3000   
  4.   BalancerMember http://localhost:3001   
  5. </Proxy>  
  6.   
  7. <VirtualHost *:80>  
  8.   ServerName www.xxx.com   
  9.   DocumentRoot d:/rubyproject/depot/public   
  10.   ProxyPass /images !   
  11.   ProxyPass /stylesheets !   
  12.   ProxyPass /javascripts !   
  13.   ProxyPass / balancer://myCluster/   
  14.   ProxyPassReverse / balancer://myCluster/   
  15.   ProxyPreserveHost on   
  16. </VirtualHost>  

 myCluster定義了群集中的每個mongrel應用伺服器節點。ProxyPass /images !指明該URL開始的請求不代理給Mongrel群集,而由Apache自己處理。重起Apache,然後開啟瀏覽器訪問www.xxx.com,檢查配置是否正確。 至此,在Windows Server上面一個具備良好穩定性和效能的Ruby on rails生產環境就搭建好了。 對於頁面輸出,還可以使用mod_deflate進行輸出內容壓縮,以提高頁面下載速度,這個就留給大家自己配置了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.