# Handling 404 with mongrel + proxy

**URL:** <https://www.ruby-forum.com/t/handling-404-with-mongrel-proxy/126678>\
**Category:** Rails\
**Created:** [January 21, 2008, 10:54am UTC](https://www.ruby-forum.com/t/handling-404-with-mongrel-proxy/126678 "2008-01-21T10:54:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubenfonseca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rubenfonseca](https://www.ruby-forum.com/u/rubenfonseca)\
**Post date:** [January 21, 2008, 10:54am UTC](https://www.ruby-forum.com/t/handling-404-with-mongrel-proxy/126678/1 "2008-01-21T10:54:05Z")

</div>

Hi!

I have a site built on rails 2 and I want to put into production with  
Apache 2 + mod\_proxy + mongrel instances.

The problem is that, when I hit a non existing page, I expected  
mongrel to render the /404.html file for me. Since this did’t work, I  
put the “ErrorDocument /404.html” on my Apache 2 config but Apache  
seems to ignore it, since mongrel answers 404 with some HTML content  
(with the failing routing match).

Can you help me with this? I expected that mongrel rendered /404.html  
and /500.html as soon as I indicated I’m in production environment.  
Is this a mongrel responsibility or Apache?

Thank you

---

<div class="post-metadata">

**Author:** ![rubenfonseca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rubenfonseca](https://www.ruby-forum.com/u/rubenfonseca)\
**Post date:** [January 21, 2008, 1:01pm UTC](https://www.ruby-forum.com/t/handling-404-with-mongrel-proxy/126678/2 "2008-01-21T13:01:02Z")

</div>

depends on your setup.

The ideal configuration most of the time is to have Apache serve all  
static files and have mongrel serve the dispatch.rb/cgi/fcgi file.

You need to configure apache to say “if there is no matching file proxy  
to mogrel”

then have your app say "if route not found redirect\_to ‘/404’

start with your app:

there is a rescue method for controllers (check the api for the name) i  
believe its called “rescue\_action” were you can say “if route not found  
redirect else call the super” in your application controller

---

<div class="post-metadata">

**Author:** ![rubenfonseca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rubenfonseca](https://www.ruby-forum.com/u/rubenfonseca)\
**Post date:** [January 21, 2008, 1:08pm UTC](https://www.ruby-forum.com/t/handling-404-with-mongrel-proxy/126678/3 "2008-01-21T13:08:54Z")

</div>

On 2008/01/21, at 09:52, Ruben F. wrote:

> (with the failing routing match).
> 
> Can you help me with this? I expected that mongrel rendered /404.html  
> and /500.html as soon as I indicated I’m in production environment.  
> Is this a mongrel responsibility or Apache?

I was using exception\_notification plugin, and the problem was that  
exception\_notifiacation looks at the requests from the Apache (proxy)  
as local (yah… he’s right…)

The solution was to include in app/controllers/application.rb:

after “include ExceptionNotifiable”  
local\_addresses.clear

Now it works 🙂 Cheers,  
Ruben
