How to solve the problem of "405 not allowed"?

Nick Pearson nick.pearson at gmail.com
Fri Jan 29 22:30:16 MSK 2010


I know 'if' is evil, and in general shouldn't be used inside a
location block, but I needed this ability as well and have been using
the following without any trouble for a couple years.

upstream app_servers {
  server  localhost:3000;
}

server {

  # set proxy settings here (not allowed in 'if')
  proxy_set_header  X-Real-IP  $remote_addr;

  location / {
    if ($request_method = POST) {
      proxy_pass  http://app_servers;
      break;
    }
    try_files  $uri  @app;
  }

  location @app {
    proxy_pass  http://app_servers;
  }

}

If anyone has any better ideas, I'd love to hear them.  So far, I
haven't been able to find any without having to patch the source.

While we're on the topic, I know there's been talk of allowing POST
requests to static files, but I don't remember a clear behavior being
defined.  When added to nginx, will this simply serve the static file
as though a GET request was made?  Ideally, one would be able to
specify that POST requests should always be proxied to an upstream
(which is what my config above does).

Maybe something like this in the config:

  # handle just like a GET request
  allow_static_post  on;

  # proxy to upstream
  allow_static_post  proxy_pass  http://app_servers;

I don't use FCGI or PHP, so I'm not sure how the config would look for
those, but you get the idea.

Nick



On Fri, Jan 29, 2010 at 10:41 AM, kleinchris <nginx-forum at nginx.us> wrote:
> Can't edit my post...
> Here is a debug log, when i do it like this:
> error_page 405 =200 @405;
>        location = @405 {
>                root /var/www/vhosts/soulreafer;
>        }
>
> http://nopaste.info/5cf44ab3b1.html
>
> nginx version: 0.8.32
>
> Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,47301#msg-47301
>
>
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://nginx.org/mailman/listinfo/nginx
>



More information about the nginx mailing list