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

72 views
Skip to first unread message

dennis cao

unread,
Oct 8, 2009, 10:49:50 PM10/8/09
to ng...@sysoev.ru

<20090527084...@rambler-co.ru>
Content-Type: text/plain; charset="big5"
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


Is this patch build-in in the new version?
> Date: Wed, 27 May 2009 12:46:17 +0400
> From: i...@rambler-co.ru
> To: ng...@sysoev.ru
> Subject: Re: How to solve the problem of "405 not allowed"?
>
> On Wed, May 27, 2009 at 03:17:49AM -0400, peacock wrote:
>
>> When I post when a JavaScript file, "405 not allowed" error will appear.
>>
>> if use proxy, it can work.
>>
>> error_page 405 =200 @405;
>> location @405 {
>> root /htdocs;
>> proxy_pass http://localhost:8080;
>> }
>>
>>
>> but I do not want to use proxy, just want to use Nginx, can to achieve it?
>
> Try the attached patch, it allows to POST to static files.
> Probably I will include it in 0.8.0.
>
>
> --
> Igor Sysoev
> http://sysoev.ru/en/
_________________________________________________________________
下載 Windows Live Messenger 9.0,多元溝通、盡情分享,和即時傳訊好友線上同樂!— 立即下載
http://download.live.com/messenger

kleinchris

unread,
Jan 29, 2010, 11:30:12 AM1/29/10
to ng...@nginx.org
Is there a fix that I can POST on static files in nginx 0.8.32? I need this..

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,47294#msg-47294


_______________________________________________
nginx mailing list
ng...@nginx.org
http://nginx.org/mailman/listinfo/nginx

kleinchris

unread,
Jan 29, 2010, 11:41:43 AM1/29/10
to ng...@nginx.org
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

Nick Pearson

unread,
Jan 29, 2010, 2:30:16 PM1/29/10
to ng...@nginx.org
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

Maxim Dounin

unread,
Jan 29, 2010, 5:04:16 PM1/29/10
to ng...@nginx.org
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.

Maxim Dounin

Maxim Dounin

unread,
Jan 29, 2010, 5:12:45 PM1/29/10
to ng...@nginx.org
Hello!

On Fri, Jan 29, 2010 at 11:41:43AM -0500, kleinchris 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;
> }

This will return internal 405 error page, as

1. you are serving request by static module again;

2. error_page to named location doesn't change request method.

Try this instead:

error_page 405 = $uri;

This way request method will be changed to GET, and the same uri
will be used to serve it.

> http://nopaste.info/5cf44ab3b1.html

This log doesn't shows any problems, and it's not even for POST
request. Instead it shows perfectly ok GET request (returning 304
not modified, as request includes If-Modified-Since).

Maxim Dounin

kleinchris

unread,
Jan 29, 2010, 5:58:16 PM1/29/10
to ng...@nginx.org
Hm very bad to proxy, I manually applied the patch that were postet. And finally it will works.
One File I needed to edit manually, but know Igor's Patch is working.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,47475#msg-47475

locojohn

unread,
Jul 6, 2011, 7:29:27 PM7/6/11
to ng...@nginx.org
Unfortunately, I too am getting the 405 response from the SiteSupra CMS
management system when running in the admin mode:

"POST /index.php/supra/block/en/scale.php?SCALE/16100 HTTP/1.1" 405 754


However, this is a PHP script, so why does it give the 405 status?

Many thanks for suggestions

Andrejs

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,211998#msg-211998

locojohn

unread,
Jul 7, 2011, 9:25:36 AM7/7/11
to ng...@nginx.org
In my case problem was solved, as it was incorrect rewrite rule and the
PHP script never received control, hence - 405. May I suggest that all
who receive 405 responses first check whether rewrite rules are
correctly configured.

Andrejs

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,212003#msg-212003

ahu

unread,
Oct 6, 2011, 12:21:37 PM10/6/11
to ng...@nginx.org
I find this problem occurs when enable fastcgi cache with php
sometime.The nginx just treat php files as static files :(

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,216323#msg-216323

_______________________________________________
nginx mailing list
ng...@nginx.org

http://mailman.nginx.org/mailman/listinfo/nginx

ahu

unread,
Oct 6, 2011, 12:35:24 PM10/6/11
to ng...@nginx.org
ahu Wrote:
-------------------------------------------------------

> I find this problem occurs when enable fastcgi
> cache with php sometime.The nginx just treat php
> files as static files :(

p.s. I use nginx 1.1.5

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,216325#msg-216325

fernandokosh

unread,
Jan 3, 2012, 11:59:52 AM1/3/12
to ng...@nginx.org
I have the same issue here running Rails 2 apps virtual hosts on Debian
Squeeze.
In my case I, the error occur when I perform update with the PUT
method.
That's solve my problem:

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

Thank you!

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,220771#msg-220771

goldenaxez

unread,
Mar 29, 2012, 4:25:35 PM3/29/12
to ng...@nginx.org
fernandokosh Wrote:
-------------------------------------------------------

> I have the same issue here running Rails 2 apps
> virtual hosts on Debian Squeeze.
> In my case I, the error occur when I perform
> update with the PUT method.
> That's solve my problem:
>
> location / {
> error_page 405 = $uri;
> try_files $uri @unicorn_app;
> }
>
> Thank you!

Hello fernandokosh,
Thank you for your post. I tried really works.But this time I'm getting
a 500 internal server error. My site not open the directly.
I have to open www.vantila.com/index.html.

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,2414,224626#msg-224626

Reply all
Reply to author
Forward
0 new messages