yuu_nkjm blog
2011-12-07(Wed) 編集
[openSUSE][Apache][Tomcat] ApacheとTomacatの連携(jk版)
注記
jkをいれたけど,mod_proxy_ajpの方が良かった気がする.mod_proxy_ajpというパッケージがzypperで見つからないけど,mod_proxy_ajpは標準モジュールだから,apache2.2のインストールと共にインストールされるんだな.
インストール
yastでapache2とtomcat6をインストールする. (yast-> ソフトウェアインストール -> yast-http-serverをインストールした.これはやってもやらなくても良い.)
apacheモジュールのインストール
/etc/sysconfigエディタ-> Network/WWW/Apache2 -> APACHE_MODULESでjkを追加する.
/usr/sbin/httpd2 -M
として,apacheがロードしたモジュールを確認.
設定ファイルの編集
$CATALINA_HOME/conf以下にworkers.propertiesを作る.
# lv $CATALINA_HOME/conf/workers.properties worker.list=worker1 worker.worker1.port=8009 worker.worker1.host=localhost worker.worker1.type=ajp13
/usr/share/doc/packages/apache2-mod_jk/jk.confにjk.confの雛形があるので,/etc/apache2/conf.dにコピーする.
# lv /usr/share/doc/packages/apache2-mod_jk/jk.conf # simple configuration for apache (for AJP connector, modul mod_jk.so) <IfModule mod_jk.c> JkWorkersFile /etc/tomcat5/base/workers.properties JkLogFile /var/log/tomcat5/base/mod_jk.log # Log level to be used by mod_jk JkLogLevel error # The following line makes apache aware of the location of # the /servlets-examples context Alias /servlets-examples "/srv/www/tomcat5/base/webapps/servlets-examples" <Directory "/srv/www/tomcat5/base/webapps/servlets-examples"> Options Indexes FollowSymLinks allow from all </Directory> # The following line makes apache aware of the location of # the /jsp-examples context Alias /jsp-examples "/srv/www/tomcat5/base/webapps/jsp-examples" <Directory "/srv/www/tomcat5/base/webapps/jsp-examples"> Options Indexes FollowSymLinks allow from all </Directory> # The following line mounts all JSP files and the /servlet/ uri to tomcat JkMount /servlets-examples/servlet/* ajp13 JkMount /jsp-examples/*.jsp ajp13 # The following line prohibits users from directly accessing WEB-INF <Location "/jsp-examples/WEB-INF/"> AllowOverride None deny from all </Location> <Location "/servlets-examples/WEB-INF/"> AllowOverride None deny from all </Location> </IfModule>
上記設定ファイルの"Alias /servlets-examples"あたりを参考に,自分の呼び出したいサーブレットを呼び出すような設定を書けばOK.
トラブルシューティング
バーチャルホストの扱いに注意する.
Re: Apache2.2 / Tomcat6 / mod_jk / Suse 11.1 I figured out what was wrong: VirtualHosts. I configured two virtual hosts in apache. The tomcat connector (mod_jk) was included in httpd.conf in the top level, outside of a virtual host definition. I was assuming that calls to http://localhost/ would NOT be handled by a virtual host if there was no name-matching virtual host. That was wrong, ALL requests are handled by virtual hosts if you define them. If no matching host is found, the first one listed is used. Hence, moving the jk config inside a virtual host element solved the problem. So, I included the following in a VirtualHost element.