我要啦免费统计

          微藍領域

          我的學習檔案館
          posts - 19, comments - 57, trackbacks - 0, articles - 57
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          apache2.X版與Tomcat5.X整合

          Posted on 2007-11-01 15:05 hilor 閱讀(704) 評論(1)  編輯  收藏 所屬分類: J2EE
          下面來簡述一下,我配置的過程,準備工作如下:  關于apache2.X版與Tomcat5.X整合的技術文檔,在網上找了兩天,大部分都是指定使用apache2.08+tomcat5.0.16+mod_jk2.dll什么的,我用其它版本的怎樣試也不行,無奈之余,就又到網上四處找tomcat5.0.16版,TOMCAT官方網站沒有下載了,其實我是步入了一個誤區,其實盡信書則不如無書,TOMCAT無論用哪個版本,高版本大部分都兼容低版本的功能.希望各位以后網上資料參考就好了,最主要是看開源的幫助文檔才最重要,不過是E文的,慢慢看吧,帶個金山詞霸.^_^ 閑話少說,言歸正傳,下面介紹我的配置步驟吧!   前提準備工作及配置環境如下: 操作系統是,WINDOWS2K SERVICE版 jdk1.5(其實什么版本也無所謂了,1.4以上都行) TOMCAT5.0.19.exe文件,在TOMCAT官方網也沒有下載了,我以前下載的,要的話,可以發郵件給我,(5.0版本都無所謂了) apache_2.0.49-win32-x86-no_ssl.msi apache服務器(這個apache版本,因apache我不太熟,限不限定版本號,沒有測試過) 下載網址:http://archive.apache.org/dist/httpd/binaries/win32/ jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip(TOMCAT5與APACHE2 plus)//這個中間件在apache官方網有下載下載網址:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk2/binaries/win32/ 1.    安裝并測試Apache和TomCat5.0;注意事項: Apache默認端口為80,與IIS沖突,更改端口或關閉IIS, TomCat安裝完后配置環境變量。 2.    開始整合;首先,先把jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip解壓后,從modules目錄中取出來mod_jk2.so文件,復制到,apache安裝根目錄/apache2/modules/目錄下. 其次,編輯配置文件。具體的配置文件有四個,它們分別是:httpd.conf、jk2.properties、server.xml、workers2.properties。 我的配置如下: a、 修改ApacheRoot\Apache2\conf\httpd.conf 文件 1>修改web 主目錄,即將 DocumentRoot "D:/websrv/Apache2/htdocs" 改為自己的web主目錄 eg:     DocumentRoot    "D:/test/jsptest" 2>修改web 主目錄對應的目錄,即將 <Directory "D:/websrv/Apache2/htdocs">改為 eg:     <Directory "D:/test/jsptest" > 此目錄塊要與DocumentRoot的路徑對應,塊中的語法是對此塊對應Web主目錄的操作權限設置。 3>修改目錄缺省的web文件,即將 DirectoryIndex index.html index.html.var 改為 eg:      DirectoryIndex index.html index.html.var index.jsp 語法說明:當向Apache 發出請求時容器將順次去找index.html,如果沒有,將接著找index.htm,最后找index.jsp。 4>修改cgi-bin 所在目錄,即將 ScriptAlias /cgi-bin/ "D:/websrv/Apache2/cgi-bin/"改為 ScriptAlias /cgi-bin/ "D:/test/jsptest/cgi-bin/" <Directory "D:/websrv/Apache2/cgi-bin"> 改為 <Directory "D:/test/jsptest/cgi-bin"> 如果程序中需要用到cgi時修改以上兩處。 5>添加指定的虛擬目錄(別名),及其對應目錄的屬性 #這是測試用的文件夾,能執行jsp 文件。 Alias  /jmmis/           "D:/test/jsptest/jmmis/" <Directory       "D:/test/jsptest/jmmis" > AllowOverride None Options IncludesNoExec AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all </Directory>     #在web主目錄jsptest中添加了jmmis目錄語法說明:         Alias  /web程序別名/     "程序根目錄/"                            ##別忘啦最后有“/”       <Directory              "程序根目錄" >         AllowOverride None         Options IncludesNoExec         AddOutputFilter Includes html                           對此程序的具體操作權限設置            AddHandler type-map var                                           Order allow,deny        Allow from all </Directory> 注意:                    程序根目錄必須和%Tomcat5%\conf\server.xml中配置的虛擬目錄相吻合。            6>添加默認字符集的設置   AddDefaultCharset GB2312             7>在文件最后添加如下內容,以加載jk2 模塊     <IfModule !mod_jk2.c> LoadModule jk2_module modules/mod_jk2.so </IfModule> 以上都是配置httpd.conf Apache服務器的東西! 接下來配JK2了 JK2指定一個worker2.properties文件存放路徑為就是SERVERROOT/conf 這里的serverroot 是apache的安裝目錄原JK2幫助文檔顯示如下所示 workers2.properties is used on the webserver side. For the Apache servers the default path is in the ServerRoot/conf directory. worker2.properties文件如下: [shm] info=Scoreboard. Requried for reconfiguration and status with multiprocess servers. file=anon # Defines a load balancer named lb. Use even if you only have one machine. [lb:lb] # Example socket channel, override port and host. [channel.socket:localhost:8019] port=8019 host=127.0.0.1 # define the worker [ajp13:localhost:8019] channel=channel.socket:localhost:8019 group=lb # Map the Tomcat examples webapp to the Web server uri space [uri:/*.jsp] group=lb [uri:/Servlet/*] group=lb [status:] info=Status worker, displays runtime information [uri:/jkstatus/*] info=The Tomcat /jkstatus handler group=status: 接著修改JK2.properties文件,默認不用作什么修改, TOMCAT5/conf的jk2.properties文件不需太多修改,  jk2的屬性文件如下  ## THIS FILE MAY BE OVERRIDEN AT RUNTIME. MAKE SURE TOMCAT IS STOPED ## WHEN YOU EDIT THE FILE. ## COMMENTS WILL BE _LOST_ ## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.  #Set the desired handler list  handler.list=apr,request,channelJni # # Override the default port for the socketChannel  channelSocket.port=8019 # Default: # channelUnix.file=${jkHome}/work/jk2.socket # Just to check if the the config  is working # shm.file=${jkHome}/work/jk2.shm # In order to enable jni use any channelJni directive # channelJni.disabled = 0 # And one of the following directives: #apr.NativeSo=/home1/jakarta/jakarta-tomcat-connectors/jk/build/jk2/apache2/jkjni.so  apr.jniModeSo=/ApacheRoot/apache2/modules/mod_jk2.so #apr.jniModeSo=C:/Apache/Apache2/modules/mod_jk2.so # If set to inprocess the mod_jk2 will Register natives itself # This will enable the starting of the Tomcat from mod_jk2  apr.jniModeSo=inprocess #Shared memory directive shm.file=C:/Apache/Apache2/logs/jk2.shm 修改TOMCAT下/conf目錄下的server.xml文件 保持通信管道端口號一致與worker2.properties文件中, # define the worker [ajp13:localhost:8019] channel=channel.socket:localhost:8019 所定義的8019一致 <Connector port="8019"                enableLookups="true" redirectPort="8443" debug="0"                protocol="AJP/1.3" /> 同時在</host>位置增加虛擬目錄  <Context path="/jmmis" docBase="D:/test/jsptest/jmmis" debug="0" reloadable="true" crossContext="true"></Context> 這里也許會報警告信息,修改 TOMCAT/CONF/下的server-minimal.xml的文件,把默認的8009修改為8019 以上修改完成后,重啟APACHE TOMCAT就大功告成了!
          下面來簡述一下,我配置的過程,準備工作如下:
           關于apache2.X版與Tomcat5.X整合的技術文檔,在網上找了兩天,大部分都是指定使用apache2.08+tomcat5.0.16+mod_jk2.dll什么的,我用其它版本的怎樣試也不行,無奈之余,就又到網上四處找tomcat5.0.16版,TOMCAT官方網站沒有下載了,其實我是步入了一個誤區,其實盡信書則不如無書,TOMCAT無論用哪個版本,高版本大部分都兼容低版本的功能.希望各位以后網上資料參考就好了,最主要是看開源的幫助文檔才最重要,不過是E文的,慢慢看吧,帶個金山詞霸.^_^ 閑話少說,言歸正傳,下面介紹我的配置步驟吧!
           
          前提準備工作及配置環境如下:
          操作系統是,WINDOWS2K SERVICE版
          jdk1.5(其實什么版本也無所謂了,1.4以上都行)
          TOMCAT5.0.19.exe文件,在TOMCAT官方網也沒有下載了,我以前下載的,要的話,可以發郵件給我,(5.0版本都無所謂了)
          apache_2.0.49-win32-x86-no_ssl.msi apache服務器(這個apache版本,因apache我不太熟,限不限定版本號,沒有測試過)
          下載網址:http://archive.apache.org/dist/httpd/binaries/win32/
          jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip(TOMCAT5與APACHE2 plus)//這個中間件在apache官方網有下載
          下載網址:http://archive.apache.org/dist/tomcat/tomcat-connectors/jk2/binaries/win32/
          1.    安裝并測試Apache和TomCat5.0;
          注意事項: Apache默認端口為80,與IIS沖突,更改端口或關閉IIS,
          TomCat安裝完后配置環境變量。
          2.    開始整合;
          首先,先把jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip解壓后,從modules目錄中取出來mod_jk2.so文件,復制到,apache安裝根目錄/apache2/modules/目錄下.
          其次,編輯配置文件。具體的配置文件有四個,
          它們分別是:httpd.conf、jk2.properties、server.xml、workers2.properties。

          我的配置如下:

          a、 修改ApacheRoot\Apache2\conf\httpd.conf 文件
          1>修改web 主目錄,即將
          DocumentRoot "D:/websrv/Apache2/htdocs" 改為自己的web主目錄
          eg:     DocumentRoot    "D:/test/jsptest"
          2>修改web 主目錄對應的目錄,即將
          <Directory "D:/websrv/Apache2/htdocs">改為
          eg:     <Directory "D:/test/jsptest" >
          此目錄塊要與DocumentRoot的路徑對應,塊中的語法是對此塊對應Web主目錄的操作權限設置。
          3>修改目錄缺省的web文件,即將
          DirectoryIndex index.html index.html.var 改為
          eg:      DirectoryIndex index.html index.html.var index.jsp
          語法說明:當向Apache 發出請求時容器將順次去找index.html,如果沒有,將接著找index.htm,最后找index.jsp。
          4>修改cgi-bin 所在目錄,即將
          ScriptAlias /cgi-bin/ "D:/websrv/Apache2/cgi-bin/"改為
          ScriptAlias /cgi-bin/ "D:/test/jsptest/cgi-bin/"
          <Directory "D:/websrv/Apache2/cgi-bin"> 改為
          <Directory "D:/test/jsptest/cgi-bin">
          如果程序中需要用到cgi時修改以上兩處。
          5>添加指定的虛擬目錄(別名),及其對應目錄的屬性
          #這是測試用的文件夾,能執行jsp 文件。
          Alias  /jmmis/           "D:/test/jsptest/jmmis/"
          <Directory       "D:/test/jsptest/jmmis" >
          AllowOverride None
          Options IncludesNoExec
          AddOutputFilter Includes html
          AddHandler type-map var
          Order allow,deny
          Allow from all
          </Directory>
              
          #在web主目錄jsptest中添加了jmmis目錄
          語法說明:
           
                Alias  /web程序別名/     "程序根目錄/"                            ##別忘啦最后有“/”
                <Directory              "程序根目錄" >
                  AllowOverride None
                  Options IncludesNoExec
                  AddOutputFilter Includes html                           對此程序的具體操作權限設置   
                  AddHandler type-map var                                  
                  Order allow,deny
                 Allow from all
          </Directory>
          注意:
                             程序根目錄必須和%Tomcat5%\conf\server.xml中配置的虛擬目錄相吻合。
                     6>添加默認字符集的設置
            AddDefaultCharset GB2312
                      7>在文件最后添加如下內容,以加載jk2 模塊
             
          <IfModule !mod_jk2.c>
          LoadModule jk2_module modules/mod_jk2.so
          </IfModule>
          以上都是配置httpd.conf Apache服務器的東西!
          
          
          接下來配JK2了
          JK2指定一個worker2.properties文件
          存放路徑為就是SERVERROOT/conf
          這里的serverroot 是apache的安裝目錄
          原JK2幫助文檔顯示如下所示
          workers2.properties is used on the webserver side. For the Apache servers the default path is in the ServerRoot/conf directory.
          worker2.properties文件如下:

          [shm]
          info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
          file=anon
          # Defines a load balancer named lb. Use even if you only have one machine.
          [lb:lb]
          # Example socket channel, override port and host.
          [channel.socket:localhost:8019]
          port=8019
          host=127.0.0.1
          # define the worker
          [ajp13:localhost:8019]
          channel=channel.socket:localhost:8019
          group=lb
          # Map the Tomcat examples webapp to the Web server uri space
          [uri:/*.jsp]
          group=lb
          [uri:/Servlet/*]
          group=lb
          [status:]
          info=Status worker, displays runtime information
          [uri:/jkstatus/*]
          info=The Tomcat /jkstatus handler
          group=status:
          接著修改JK2.properties文件,默認不用作什么修改,
          TOMCAT5/conf的jk2.properties文件不需太多修改,
           jk2的屬性文件如下
           ## THIS FILE MAY BE OVERRIDEN AT RUNTIME. MAKE SURE TOMCAT IS STOPED
          ## WHEN YOU EDIT THE FILE.
          ## COMMENTS WILL BE _LOST_
          ## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.
           #Set the desired handler list
           handler.list=apr,request,channelJni
          #
          # Override the default port for the socketChannel
           channelSocket.port=8019
          # Default:
          # channelUnix.file=${jkHome}/work/jk2.socket
          # Just to check if the the config  is working
          # shm.file=${jkHome}/work/jk2.shm
          # In order to enable jni use any channelJni directive
          # channelJni.disabled = 0
          # And one of the following directives:
          #apr.NativeSo=/home1/jakarta/jakarta-tomcat-connectors/jk/build/jk2/apache2/jkjni.so
           apr.jniModeSo=/ApacheRoot/apache2/modules/mod_jk2.so
          #apr.jniModeSo=C:/Apache/Apache2/modules/mod_jk2.so
          # If set to inprocess the mod_jk2 will Register natives itself
          # This will enable the starting of the Tomcat from mod_jk2
           apr.jniModeSo=inprocess
          #Shared memory directive
          shm.file=C:/Apache/Apache2/logs/jk2.shm
          修改TOMCAT下/conf目錄下的server.xml文件

          保持通信管道端口號一致
          與worker2.properties文件中,
          # define the worker
          [ajp13:localhost:8019]
          channel=channel.socket:localhost:8019
          所定義的8019一致
          <Connector port="8019"
                         enableLookups="true" redirectPort="8443" debug="0"
                         protocol="AJP/1.3" />
          同時在</host>位置增加虛擬目錄
           <Context path="/jmmis" docBase="D:/test/jsptest/jmmis" debug="0" reloadable="true"
          crossContext="true"></Context>
          這里也許會報警告信息,修改 TOMCAT/CONF/下的server-minimal.xml的文件,把默認的8009修改為8019
          以上修改完成后,重啟APACHE TOMCAT就大功告成了!

          評論

          # re: apache2.X版與Tomcat5.X整合  回復  更多評論   

          2007-11-29 23:34 by domando
          多謝,終于看到一個像樣子的配置文章。
          主站蜘蛛池模板: 仪陇县| 扎鲁特旗| 昆明市| 漠河县| 安福县| 苏尼特左旗| 吴忠市| 分宜县| 科尔| 玉龙| 凤山市| 田林县| 巴林右旗| 奉贤区| 沽源县| 德化县| 英超| 马关县| 桐乡市| 河北省| 上思县| 鄂伦春自治旗| 辉南县| 洛宁县| 龙游县| 炎陵县| 子长县| 衡水市| 赣州市| 中牟县| 大邑县| 乐昌市| 南投市| 陇西县| 邢台市| 元朗区| 任丘市| 治多县| 子长县| 三亚市| 宝应县|