The importance of monitoring 404 errors

Munin will graph any virtualhost 404 errors, as well as the centralised logging - which is a very important tool for keeping up high performance on a Magento store.

404 errors on static content will lead to the Magento bootstrap (index.php) being loaded in place of content. Even with the fastest of stores, a call to index.php can come at a minimum cost of 80ms.

If you multiply that by the number of 404 elements on your page, it can really add up.

Configuring a 404 error page for static content

We still want dynamic 404's to hit Magento, but for any static content (eg. CSS/JS/images) - its much better to serve a plain placeholder HTML page than hit the Magento bootstrap needlessly.

  1. All you need to do is create a directory (which usually already exists on a Magento store) called ./errors
  2. Within this directory, create a file called 404.html and customise it however you wish.

Then to test if your changes have worked, just visit your website and try and view a non-existent URL

Eg. https://www.example.com/my-non-existent-url.jpg

Sample 404.php

The default Magento 404.php looks like this, which you can style with the respective design.xml and default template directory in the ./errors directory. This is a good mechanism and does not introduce too much overhead - and allows for easier deployment of custom 404 pages for different stores, but if you want an extremely lightweight version, use the pure PHP/HTML alternative below.

<?php
  require_once 'processor.php';
  $processor = new Error_Processor();
  $processor->process404();

Alternatively, if you want something simpler, you can use ordinary PHP/HTML to achieve the same result.

<?php
  header("HTTP/1.0 404 Not Found");
?>
<html>
  ...
</html>

Configuring a 404 error page for dynamic content

At present, we still let all dynamic content hit Magento's bootstrap - as the server cannot distinguish what is or isn't a real URL.

But this doesn't mean that you should ignore 404 dynamic content. 404 pages for Magento are very costly; as the response is not cached by Magento - so each time someone hits a 404 page, it is consuming server resources.

It is a good idea to regularly review logs and add Nginx rewrite rules to redirect 404 content with a 302 or 301 status back to your homepage (or a suitable replacement page).

Finding 404 errors

Via Kibana

Access either the load balancer or web server Kibana dashboard

Then use the search string

response_code:"404"