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


#1

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?

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


#2

What response do you expect to receive when you issue

POST /javascript.js HTTP/1.1

Cheers

Dave

peacock writes:


#3

sorry, my english is poor, I have listed some of the information

error_page 405 =200 @405;
location @405 {
root /htdocs;
#proxy_pass http://localhost:8080;
}

(ajax)POST:
http://localhost/…/index.js

Response:

405 Not Allowed

405 Not Allowed
nginx/0.7.59

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


#4

NginX does not allow posts to static content. But Igor has posted a
workaround
http://article.gmane.org/gmane.comp.web.nginx.english/1941/match=post+405+static

Rob S.


#5

On Wed, May 27, 2009 at 03:17:49AM -0400, peacock wrote:

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.


#6

On Wed, May 27, 2009 at 05:38:02AM -0400, peacock wrote:

Unfortunately, this workaround is still not working properly :frowning:

Response:

500 Internal Server Error

500 Internal Server Error
nginx/0.7.59

Could you create debug log of the request ?

./configure --with-debug …

nginx.conf:

error_log /path/to/log debug;


#7

Igor S. Wrote:

Try the attached patch, it allows to POST to
static files.
Probably I will include it in 0.8.0.


Igor S.
http://sysoev.ru/en/

I’m sorry, I do not see your reply:)

I use Windows, so I do not know how to run the patch.

Hope to be able to add this feature 0.8.0:)

thank you very much!

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


#8

removed_email_address@domain.invalid
Content-Type: text/plain; charset=“big5”
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0

Is this patch build-in in the new version?


#9

Unfortunately, this workaround is still not working properly :frowning:

Response:

500 Internal Server Error

500 Internal Server Error
nginx/0.7.59

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


#10

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


#11

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


#12

Hello!

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

set proxy settings here (not allowed in ‘if’)

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).

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 D.


#13

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


#14

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 D.


#15

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


#16

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


#17

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


#18

ahu Wrote:

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

p.s. I use nginx 1.1.5

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


#19

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

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


#20

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