# 404 Method Not Allowed when returning 500 error to POST request

**URL:** <https://www.ruby-forum.com/t/404-method-not-allowed-when-returning-500-error-to-post-request/204970>\
**Category:** NGINX\
**Created:** [March 25, 2011, 9:03pm UTC](https://www.ruby-forum.com/t/404-method-not-allowed-when-returning-500-error-to-post-request/204970 "2011-03-25T21:03:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 25, 2011, 9:03pm UTC](https://www.ruby-forum.com/t/404-method-not-allowed-when-returning-500-error-to-post-request/204970/1 "2011-03-25T21:03:01Z")

</div>

Hi there,

I have what I consider to be an excellent configuration for how I’m  
handling error pages with nginx running as a load balancer reverse proxy  
in front of Apache. In a nutshell, if the upstream apache webserver  
returns an error (let’s say a 500), nginx will first check for an error  
page in the current server folder (/var/www/currentserver.com/500.html)  
and then if no file is found there, it checks a “default” folder  
(/var/www/default/500.html). This is accomplished via the following  
configuration:

```
server {
    root /var/www/someserver.com/;

    error_page 404 = @not_found;
    error_page 500 502 504 = @server_error;
    error_page 503 = @maintenance;

    location @not_found {
        try_files /404.html /../default/404.html =404;
    }

    location @server_error {
        try_files /500.html /../default/500.html =500;
    }

    location @maintenance {
        try_files /503.html /../default/503.html =503;
    }
}

```

This worked well for me during testing, however I recently ran into a  
problem:

When Apache returns a 500 server error in a POST request, instead of  
getting the 500 response and page I normally would with a GET, I get a  
405 Not Allowed response. (The error page is correct when I trigger a  
500 with a GET.)

As far as I can tell, what is happening is that try\_files is preserving  
the request method of the _main_ request as opposed to trying to simply  
GET the file for the purposes of returning an error. Since 500.html is  
static content, it’s basically trying to POST to static content, which I  
have read does not work at present.

I’m trying to figure out how best to proceed. One thought is that this  
is perhaps a bug? In a sub request I don’t see how it makes sense for  
nginx to preserve the original request…well, at least not in the case  
of error pages. You are never going to POST to an error page, you are  
only every going to retrieve one via GET. But perhaps I am combining  
error\_page, fallback locations, and try\_files in an unconventional way  
that it is not supported or otherwise ill advised.

The hack I will probably pursue is finding a way to catch the 405 errors  
within these locations but I haven’t found a workaround just yet.

Anyhow, any advice or guidance would be immensely appreciated. Thank you  
very much.

Posted at Nginx Forum:

> **[404 Method Not Allowed when returning 500 error to POST request](https://forum.nginx.org/read.php?2,185782,185782#msg-185782)**
>
> Hi there, I have what I consider to be an excellent configuration for how I'm handling error pages with nginx running as a load balancer reverse proxy in front of Apache. In a nutshell, if the upstream apache webserver returns an error (let's say a...

---

<div class="post-metadata">

**Author:** ![jsdalton](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@jsdalton](https://www.ruby-forum.com/u/jsdalton)\
**Post date:** [March 25, 2011, 10:21pm UTC](https://www.ruby-forum.com/t/404-method-not-allowed-when-returning-500-error-to-post-request/204970/2 "2011-03-25T22:21:22Z")

</div>

Gah, just realized I got the title of this post wrong. I of course meant  
_405_ Not Allowed, not 404!

Posted at Nginx Forum:

> **[Re: 404 Method Not Allowed when returning 500 error to POST request](https://forum.nginx.org/read.php?2,185782,185802#msg-185802)**
>
> Hi there, I have what I consider to be an excellent configuration for how I'm handling error pages with nginx running as a load balancer reverse proxy in front of Apache. In a nutshell, if the upstream apache webserver returns an error (let's say a...
