原文:http://hi.baidu.com/mygia/blog/item/c3b53da8e336cfa6ca130cb2.html
Apache 是一個出色的 http 伺服器, 跟resin和tomcat這些web伺服器不同,它不能解釋動態網頁面,但作為伺服器來解釋html、js等靜態檔案比web伺服器有效得多。而且apache還提供多方面的管理。Apache 可以整合resin或tomcat,當作高效又穩定的web server。
1 配置 Apache(one) + resin (one)
Apache 2.0.55 resin 3.0.19
配置 Apache + resin 當網頁伺服器要比單獨用resin來做web server優秀的多。Resin的協助文檔也提供和Apache整合的資料。
首先,必先確保你的resin 和 Apache可以單獨運行。Resin的安裝和測試這裡省略。Apache的安裝非常簡單。只需要預設安即可,中間只需要填寫你的email。(我安裝的是Apache 2.0.55)Apache安裝後預設連接埠是80 。安裝好測試http://localhost/, 若安裝成功將顯示成功測試的頁面。確保你的resin 和 Apache可以單獨運行後,修改Apache設定檔 conf/httpd.conf ,在後面加上如下一段。
LoadModule caucho_module <%resin_home%>/win32/apache-2.0/mod_caucho.dll
ResinConfigServer 192.169.100.15 6802
<locationcaucho-status="">
SetHandler caucho-status
</location>
註:<%resin_home%>代表resin安裝目錄,到時請將具體目錄替代它。
這段的意思是為Apache加上一個外掛程式,Apache以LoadModule ****_module文法載入外掛程式。****_module為外掛程式的名字,後面的是外掛程式的檔案地址。caucho_module這個外掛程式就是resin提供的,是Apache和resin通訊的中介軟體,一般放在resin安裝目錄下的win32/apache-x.x/下(resin 3.0.19),apache-x.x目錄一般有多個,你只要選擇符合你的acpache版本的就可以。
或者你可以將相應的apache-x.x目錄下的mod_caucho.dll檔案複製到apche的外掛程式檔案夾內(<%apache_home%>/modules/)。然後使用相對路徑。如
LoadModule caucho_module modules/mod_caucho.dll
而下一句中“192.169.100.15 ”代表的是resin所在機器的IP,“6802”是預設連接埠。然後修改resin的設定檔conf/resin.conf。找到這幾行:
<cluster>
<srunserver-id=""host="127.0.0.1"port="6802">
</srun>
如果它們已經被注釋,去掉注釋符號,且務必要使這裡的連接埠(如: port="6802")與剛才在resin設定檔中的ResinConfigServer 192.169.100.15 6802 這句話裡配置的連接埠一致,如果你沒有使用6802這個預設連接埠的話。192.169.100.15也應該與127.0.0.1相對應,它們都是指resin所在機器的IP,如果resin與apache同在一部機器,且<srunserver-id=""host="127.0.0.1"port="6802">這裡使用127.0.0.1那麼在ResinConfigServer
192.169.100.15 6802中應該將192.169.100.15改為localhost或127.0.0.1。就是說如果用了具體的IP如192.169.100.15,那麼兩個地方都要用具體的IP。
配置成功後開啟http://localhost/caucho-status 可看到伺服器的配置詳細結果。
Apache (one)+ resin (one) 工作流程圖如下:
這時訪問apache就可訪問到resin裡配置的項目。Apache負責項目裡的靜態檔案,resin則充當jsp/servlet解釋伺服器。像項目裡這樣的http://localhost/tianyacity/js/pageFunc.js (或html檔案)則預設由apache 來解釋,它將在apache裡配置的項目和預設訪問路徑<%apache_home%>/htdocs/裡尋找http://localhost/tianyacity/js/pageFunc.js這個路徑,它不會到resin裡配置的項目裡尋找。所以要在<%apache_home%>/htdocs/裡加上這個目錄/tianyacity/js/pageFunc.js
又或者在apache設定檔httpd.conf裡配置一個項目:
Alias /tianyacity/ "D:/workspace2006/tianyaCity/web/"
<directoryd:=""workspace2006=""tianyacity=""web="">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</directory>
Alias /tianyacity/ 這裡的/tianyacity/是訪問路徑名,與在resin配置的項目tiayacity的訪問最好一致。
2 配置 Apache(one)+ resin (many)叢集
Apache 2.0.55 resin 3.0.19
配置 Apache + resin 叢集只需要在Apache(one)+ resin (one)的基礎上修改Apache 和 resin的設定檔。
修改Resin 設定檔如下:
<httpserver-id="pan"host="*"port="8010">
<!--
- SSL port configuration:
-
- <http port="8443">
- <openssl>
- <certificate-file>keys/gryffindor.crt</certificate-file>
- <certificate-key-file>keys/gryffindor.key</certificate-key-file>
- <password>test123</password>
- </openssl>
- </http>
-->
<!--
- The local cluster, used for load balancing and distributed
- backup.
-->
<cluster>
<srunserver-id="pan"host="192.169.100.15"port="6802"index="”1”/">
<srunserver-id="he"host="192.169.100.16"port="6802"index="”2”/">
</srun>
………..
<srunserver-id="pan"host="192.169.100.15"port="6802"index="”1”/">
<srunserver-id="he"host="192.169.100.16"port="6802"index="”1”/">這樣表示將IP為15和16的兩台伺服器作為一個叢集。叢集內的server-id不能相同。而原生server-id 必須與設定檔中<httpserver-id="pan"host="*"port="8010">中的server-id
一致。因為resin預設的server-id為空白(server-id=“”)所以修改後要加 –server 參數才能正確啟動resin。在命令視窗(cmd)中去到resin安裝目錄,打入:
httpd.exe –server “pan”
將可正確啟動resin。
修改Apache設定檔如下:
LoadModule caucho_module modules/mod_caucho.dll
ResinConfigServer 192.169.100.15 6802
ResinConfigServer 192.169.100.16 6802
<locationcaucho-status="">
SetHandler caucho-status
</location>
只需要在原來配置的基礎上加上這一行
ResinConfigServer 192.169.100.16 6802
表示將16號機器上的resin也註冊到apache中。這時涉及到兩台伺服器,在這裡最好將Apache 和 resin的通訊外掛程式複製到apche的外掛程式檔案夾內(<%apache_home%>/modules/)。
其實apche只需要知道一台主resin伺服器即可,所以Apache設定檔在原來配置的基礎上可以不用修改,由主resin伺服器負責找到其他resin伺服器。不過這樣如果主resin伺服器壞掉,將引發其它問題。所以推薦將所有resin伺服器都註冊到apache上。
配置完成後,開啟http://localhost/caucho-status 可看到伺服器的配置詳細結果。所有註冊到apache上的resin伺服器都可以看到,沒有註冊到apache上的將不會顯示。