:::: MENU ::::

Handling HTTP errors with Apache and Tomcat using mod_jk

  • Mar 07 / 2014
  • 0

Handling HTTP errors with Apache and Tomcat using mod_jk

When you are working with web server in frontend (Apache in this example) and backend application servers (Tomcat here), you may wish to customize your error pages depending on the HTTP error code returned (either from the web server or application server).


For the following example, you will need as pre-requisites at least those versions:

  • Web Server Apache >= 2.2.x
  • Mod JK >= 1.2.27 (rule extensions are not available in earlier versions)

Apache configuration

If you want to handle any error coming from your web server or from your application servers, you will need to perform some changes in your configuration to allow the handling. First of all you will need to set up some parameters in your Apache configuration file (in apache2.conf file directly or in your VirtualHost definitions).

In my example, I am handling any HTTP error code between:

  • HTTP 400 and HTTP 405
  • HTTP 500 and 504

I am using an only file (written in PHP) allowing me to send back a simple HTML page to the user depending on the HTTP error code received.

Here is what I’ve configured in my apache2.conf file for handling any error listed above:

The errorhandler.php file could be like that (feel free to customize it as you want with a beautiful CSS theme, for the example I’ve used a basic configuration ;)):

mod_jk configuration

Once you’re done with the main configuration of Apache, you will have to specify to Apache that you want to handle any HTTP error coming from the application servers. For that, you will have to use the rule extension use_server_errors when mounting an access point to a worker through mod_jk.

By default, for a mounting point you are using:

But if you want to handle any HTTP 40x error coming from this worker, you will have to add the use_server_errors extension to your mounting point:

To handle any HTTP 50x error:

Or another option to handle both errors using just one command:

You are now handling any error received from your application server with your web server allowing you to customize it as you want.

Feel free to read more about this rule extension on the official website.

Leave a comment

You must be logged in to post a comment.

Question ? Contact