|
J'ai eu beau Googeliser un tas de fois sur le sujet, impossible de trouver une solution fiable et surtout complète pour l'affichage de pages d'erreurs personnalisées dans le cadre d'une architecture Apache - Mod-jk - Tomcat. J'ai fait pleins d'essais pour trouver une solution à la question "est-il possible de faire des pages d'erreurs HTTP personnalisées pour l'ensemble des application tournant sur Tomcat et pour l'ensemble du serveur Web?".
En effet, il est assez simple et connu de mettre des pages d'erreurs HTTP pour un serveur Web Apache via son fichier de configuration, en ajoutant le code suivant dans le fichier httpd.conf: ErrorDocument 401 /errors/error401.html ErrorDocument 402 /errors/error402.html ErrorDocument 403 /errors/error403.html ErrorDocument 404 /errors/error404.html ErrorDocument 405 /errors/error405.html ErrorDocument 406 /errors/error406.html ErrorDocument 407 /errors/error407.html ErrorDocument 408 /errors/error408.html ErrorDocument 409 /errors/error409.html ErrorDocument 410 /errors/error410.html ErrorDocument 411 /errors/error411.html ErrorDocument 412 /errors/error412.html ErrorDocument 413 /errors/error413.html ErrorDocument 414 /errors/error414.html ErrorDocument 415 /errors/error415.html ErrorDocument 500 /errors/error500.html ErrorDocument 501 /errors/error501.html ErrorDocument 502 /errors/error502.html ErrorDocument 503 /errors/error503.html ErrorDocument 504 /errors/error504.html ErrorDocument 505 /errors/error505.html
Ces pages seront rendues si le serveur Apache n'arrive pas à répondre correctement à une requête HTTP. Là, pas de souci, on designe nos pages et on les mets dans un répertoire à la racine du site. D'un autre côté si on a une application Web tournant sur Tomcat, il est aussi assez simple de mettre des pages d'erreures, en spécifiant dans le fichier web.xml de son application: <error-page><error-code>400</error-code><location>/errors/error400.html</location></error-page> <error-page><error-code>401</error-code><location>/errors/error401.html</location></error-page> <error-page><error-code>402</error-code><location>/errors/error402.html</location></error-page> <error-page><error-code>403</error-code><location>/errors/error403.html</location></error-page> <error-page><error-code>404</error-code><location>/errors/error404.html</location></error-page> <error-page><error-code>405</error-code><location>/errors/error405.html</location></error-page> <error-page><error-code>406</error-code><location>/errors/error406.html</location></error-page> <error-page><error-code>407</error-code><location>/errors/error407.html</location></error-page> <error-page><error-code>408</error-code><location>/errors/error408.html</location></error-page> <error-page><error-code>409</error-code><location>/errors/error409.html</location></error-page> <error-page><error-code>410</error-code><location>/errors/error410.html</location></error-page> <error-page><error-code>411</error-code><location>/errors/error411.html</location></error-page> <error-page><error-code>412</error-code><location>/errors/error412.html</location></error-page> <error-page><error-code>413</error-code><location>/errors/error413.html</location></error-page> <error-page><error-code>414</error-code><location>/errors/error414.html</location></error-page> <error-page><error-code>415</error-code><location>/errors/error415.html</location></error-page> <error-page><error-code>500</error-code><location>/errors/error500.html</location></error-page> <error-page><error-code>501</error-code><location>/errors/error501.html</location></error-page> <error-page><error-code>502</error-code><location>/errors/error502.html</location></error-page> <error-page><error-code>503</error-code><location>/errors/error503.html</location></error-page> <error-page><error-code>504</error-code><location>/errors/error504.html</location></error-page> <error-page><error-code>505</error-code><location>/errors/error505.html</location></error-page> Dans ce cadre là, il faut aussi mettre dans son appli web (généralement un WAR) un répertoire avec les pages pour les différentes erreures HTTP.Ceci permet de spécifier des pages d'erreurs qui auront le look de l'application, ce qui est un plus. Le dernier point, et c'est là que le bas blesse, il faut selon la configuration du worker faisant le lien entre Apache et Tomcat, spécifier des pages d'erreur pour l'ensemble du serveur applicatif tomcat, car on ne sera peut être pas dans le contexte de l'application dans tous les cas. Exemple: J'ai la configuration de worker pour le mod-jk suivant (c'est un peu biscornu, mais cela arrive parfois... preuve en est que c'est comme ça sur un de nos projets): JkMount /*.jsp wrkr JkMount /application1/* wrkr JkMount /application2/* wrkr
Cette configuration laissera Tomcat répondre aux requêtes concernant l'application1 , l'application2, mais aussi les différentes pages qui auraient l'extension jsp (allez savoir pourquoi...). Si une requête bidon comme http://www.site.com/application1/bidon.jsp arrive... alors la page d'erreur spécifiée dans le web.xml de l'application1 sera rendue. Si une requête bidon comme http://www.site.com/application2/bidon.jsp arrive... alors la page d'erreur spécifiée dans le web.xml de l'application2 sera rendue. Si une requête bidon comme http://www.site.com/bidon.jsp arrive... alors le serveur applicatif Tomcat prendre la main (car c'est spécifié dans le worker), et il ne pourra rendre aucune page d'erreur et affichera sa page d'erreur standard avec les numéros de version du serveur qui apparaissent (ce qu'on ne souhaite en aucun cas). Donc pour résoudre ce dernier point, il faut spécifier dans le web.xml de tomcat (celui spécifiant la configuration de l'application racine de Tomcat tomcat/conf/web.xml), les pages d'erreur: <error-page><error-code>400</error-code><location>/errors/error400.html</location></error-page> <error-page><error-code>401</error-code><location>/errors/error401.html</location></error-page> <error-page><error-code>402</error-code><location>/errors/error402.html</location></error-page> <error-page><error-code>403</error-code><location>/errors/error403.html</location></error-page> <error-page><error-code>404</error-code><location>/errors/error404.html</location></error-page> <error-page><error-code>405</error-code><location>/errors/error405.html</location></error-page> <error-page><error-code>406</error-code><location>/errors/error406.html</location></error-page> <error-page><error-code>407</error-code><location>/errors/error407.html</location></error-page> <error-page><error-code>408</error-code><location>/errors/error408.html</location></error-page> <error-page><error-code>409</error-code><location>/errors/error409.html</location></error-page> <error-page><error-code>410</error-code><location>/errors/error410.html</location></error-page> <error-page><error-code>411</error-code><location>/errors/error411.html</location></error-page> <error-page><error-code>412</error-code><location>/errors/error412.html</location></error-page> <error-page><error-code>413</error-code><location>/errors/error413.html</location></error-page> <error-page><error-code>414</error-code><location>/errors/error414.html</location></error-page> <error-page><error-code>415</error-code><location>/errors/error415.html</location></error-page> <error-page><error-code>500</error-code><location>/errors/error500.html</location></error-page> <error-page><error-code>501</error-code><location>/errors/error501.html</location></error-page> <error-page><error-code>502</error-code><location>/errors/error502.html</location></error-page> <error-page><error-code>503</error-code><location>/errors/error503.html</location></error-page> <error-page><error-code>504</error-code><location>/errors/error504.html</location></error-page> <error-page><error-code>505</error-code><location>/errors/error505.html</location></error-page> et poser un répertoire contenant ces pages dans le dossier ROOT (tomcat/webapps/ROOT) du serveur applicatif (même si la racine du serveur n'est accessible nulle part, elle sera utilisée pour rendre les pages d'erreurs http qui pourrait ne pas avoir été définies dans les diverses applications qui tournent ce qui est une sécurité supplémentaire). Voilà j'espère avoir été assez clair. |