atom feed25 messages in ru.sysoev.nginxRe: How to solve the problem of "405 ...
FromSent OnAttachments
peacockMay 27, 2009 12:17 am 
Dave CheneyMay 27, 2009 12:28 am 
peacockMay 27, 2009 1:37 am 
Igor SysoevMay 27, 2009 1:45 am.Other
Rob SchultzMay 27, 2009 1:56 am 
peacockMay 27, 2009 2:37 am 
Igor SysoevMay 27, 2009 8:07 am 
peacockMay 27, 2009 9:14 am 
Cliff WellsJul 24, 2009 12:15 pm 
Igor SysoevJul 24, 2009 12:25 pm.Other
Jonathan VanascoJul 24, 2009 2:00 pm 
peacockJul 28, 2009 8:44 pm 
dennis caoOct 8, 2009 7:49 pm 
kleinchrisJan 29, 2010 8:29 am 
kleinchrisJan 29, 2010 8:41 am 
Nick PearsonJan 29, 2010 11:29 am 
Maxim DouninJan 29, 2010 2:03 pm 
Maxim DouninJan 29, 2010 2:12 pm 
kleinchrisJan 29, 2010 2:57 pm 
locojohnJul 6, 2011 4:28 pm 
locojohnJul 7, 2011 6:24 am 
ahuOct 6, 2011 9:20 am 
ahuOct 6, 2011 9:34 am 
fernandokoshJan 3, 2012 8:59 am 
goldenaxezMar 29, 2012 1:24 pm 
Subject:Re: How to solve the problem of "405 not allowed"?
From:Maxim Dounin (mdou@mdounin.ru)
Date:Jan 29, 2010 2:03:50 pm
List:ru.sysoev.nginx

Hello!

On Fri, Jan 29, 2010 at 01:30:16PM -0600, Nick Pearson wrote:

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.

The above configuration will work, but expect problems once you'll add another if. I personally suggest something like:

location / { error_page 405 = @app; try_files $uri @app; }

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

As static module will return 405 for POST request this is mostly identical to what you currently has (though it will also pass to app servers other methods unknown to static module, e.g. PUT).

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.

I see no problem using error_page to handle this.