「tomcat」カテゴリーアーカイブ

mod_jk apache tomcat連携 エラーページのカスタマイズ

mod_jkを使用して、apache-tomcat連携で、エラーページをカスタマイズするには
やはり、httpd.conf とweb.xmlの両方に設定がいるようです。
 
なので、webapps/app/error/エラーページと、
apacheからみる/var/www/html/error/エラーページのような
配置が必要。
 
tomcat起動時にはapache側にエラーを流せませんので、
web.xmlの設定に沿ってページが表示されます。
 
tomcat停止時にはhttpd.confの設定に沿って
ページが表示されます。
 
LocationMatchディレクティブを使用することで
各アプリに別にエラーページを表示できます。
webappsにapp1とapp2を配置してエラーを分ける場合。
■web.xml
app1とapp2の両方
<!– ▼▼▼▼▼ エラー頁 ▼▼▼▼▼ –>
<!–
  <error-page>
    <error-code>400</error-code>
    <location>/error/400.html</location>
  </error-page>
  <error-page>
    <error-code>403</error-code>
    <location>/error/403.html</location>
  </error-page>
  <error-page>
    <error-code>404</error-code>
    <location>/error/404.html</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/error/500.html</location>
  </error-page>
  <error-page>
    <error-code>503</error-code>
    <location>/error/503.html</location>
  </error-page>
–>
<!– ▲▲▲▲▲ エラー頁 ▲▲▲▲▲ –>
■httpd.conf
Alias /error/ “/var/www/html/errorpage/”
<Directory “/var/www/html/errorpage”>
    適切なパラメータ
</Directory>
Alias /error2/ “/var/html/errorpage2/”
<Directory “/var/www/html/errorpage2”>
    適切なパラメータ
</Directory>
<LocationMatch “.*/app1/.*”>
ErrorDocument 400 /error/400.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
ErrorDocument 503 /error/503.html
</LocationMatch>
<LocationMatch “.*/app2/.*”>
ErrorDocument 400 /error2/400.html
ErrorDocument 403 /error2/403.html
ErrorDocument 404 /error2/404.html
ErrorDocument 500 /error2/500.html
ErrorDocument 503 /error2/503.html
</LocationMatch>

tomcatのエラーページをカスタマイズする方法。

tomcat で webページを表示するときに、エラーになると通常は。tomcatが用意したエラーページが出る。

それだとかっこ悪いので、web.xmlに以下のように記述すると、httpステータスコードに対応した

カスタマイズしたページが表示できる。

  <error-page>
    <error-code>400</error-code>
    <location>/error/400.html</location>
  </error-page>
  <error-page>
    <error-code>403</error-code>
    <location>/error/403.html</location>
  </error-page>
  <error-page>
    <error-code>404</error-code>
    <location>/error/404.html</location>
  </error-page>
  <error-page>
    <error-code>500</error-code>
    <location>/error/500.html</location>
  </error-page>
  <error-page>
    <error-code>503</error-code>
    <location>/error/503.html</location>
  </error-page>