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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
2974d09ac2541e892966b762aad84943?d=identicon&s=25 peacock (Guest)
on 2009-05-27 09:27
(Received via mailing list)
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
Fda08117336cfde6562315df04b976e8?d=identicon&s=25 Dave Cheney (Guest)
on 2009-05-27 09:34
(Received via mailing list)
What response do you expect to receive when you issue

POST /javascript.js HTTP/1.1

Cheers

Dave

peacock writes:
2974d09ac2541e892966b762aad84943?d=identicon&s=25 peacock (Guest)
on 2009-05-27 10:47
(Received via mailing list)
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
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-27 11:01
(Received via mailing list)
Attachment: patch.static_post.1 (20 KB)
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.
C996e830c7dc59a5e8db36dff386325f?d=identicon&s=25 Rob Schultz (schultz)
on 2009-05-27 11:06
(Received via mailing list)
NginX does not allow posts to static content. But Igor has posted a
workaround
http://article.gmane.org/gmane.comp.web.nginx.engl...

Rob Schultz
2974d09ac2541e892966b762aad84943?d=identicon&s=25 peacock (Guest)
on 2009-05-27 11:49
(Received via mailing list)
Unfortunately, this workaround is still not working properly :(

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
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-27 17:22
(Received via mailing list)
On Wed, May 27, 2009 at 05:38:02AM -0400, peacock wrote:

> Unfortunately, this workaround is still not working properly :(
>
> 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;
2974d09ac2541e892966b762aad84943?d=identicon&s=25 peacock (Guest)
on 2009-05-28 11:28
(Received via mailing list)
Igor Sysoev Wrote:
>
> 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/

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
7ce625ba598c1198061bdf1b1a1353a5?d=identicon&s=25 dennis cao (Guest)
on 2009-10-09 04:59
(Received via mailing list)
<20090527084617.GD60957@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?
2974d09ac2541e892966b762aad84943?d=identicon&s=25 kleinchris (Guest)
on 2010-01-29 17:30
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 kleinchris (Guest)
on 2010-01-29 17:41
(Received via mailing list)
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
Ed6583386f2b2d56e1b5eb2ee236da39?d=identicon&s=25 Nick Pearson (Guest)
on 2010-01-29 20:30
(Received via mailing list)
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
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2010-01-29 23:05
(Received via mailing list)
Hello!

On Fri, Jan 29, 2010 at 01:30:16PM -0600, Nick Pearson 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 Dounin
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2010-01-29 23:13
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 kleinchris (Guest)
on 2010-01-29 23:58
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 locojohn (Guest)
on 2011-07-07 01:29
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 locojohn (Guest)
on 2011-07-07 15:26
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 ahu (Guest)
on 2011-10-06 18:22
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 ahu (Guest)
on 2011-10-06 18:35
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 fernandokosh (Guest)
on 2012-01-03 18:00
(Received via mailing list)
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
2974d09ac2541e892966b762aad84943?d=identicon&s=25 goldenaxez (Guest)
on 2012-03-29 22:26
(Received via mailing list)
fernandokosh Wrote:
-------------------------------------------------------
>
> 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
B1c6ff48ea7020e5896c47d8def53684?d=identicon&s=25 helluvanag .. (helluvanag_)
on 2013-09-10 09:28
Hi,
  In all the above posts a code snippet has been given to rectify the
405 error. But i wondering where exactly that code snippet has to be
added(i mean in which file of the server box). If anyone can explain a
bit elaborately, i would be grateful.

Thanks and Regards,
Nagender
This topic is locked and can not be replied to.