8

Everything worked before problems with Winginx occurred. When I send data with Jquery with POST method I get 405 (Not Allowed) error. GET works perfectly fine.

When I request data from /formcheck (which is forcmcheck.php and works fine on its own) I get this error. I ain't changed anything in Nginx logs except few lines for rewrite engine.

You can see logs:

127.0.0.1 - - [07/Jun/2017:15:14:06 +0300] "POST /formcheck HTTP/1.1" 405 575 "http://music-portfolio.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
127.0.0.1 - - [07/Jun/2017:15:16:35 +0300] "POST /formcheck HTTP/1.1" 405 575 "http://music-portfolio.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
127.0.0.1 - - [07/Jun/2017:15:17:32 +0300] "POST /formcheck HTTP/1.1" 405 575 "http://music-portfolio.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

Here is everything okay, except any data was transferred.

I don't know how or where POST can be blocked, but I need it to be allowed...

1
  • Looks like this is a popular question now. I don't really know what actually happened back there but after some weird magic with winginx it actually worked. But anyway I deleted it instantly after like 3 problems of this type and now I use openserver/xampp/vagrant. The first one is pretty easy to use and does everything automatically on windows. I would be really happy if this helps someone.
    – Telion
    Sep 9, 2017 at 3:57

1 Answer 1

12

Usually these error messages are caused by the limitation that Nginx can't serve static content on POST request. This issue is discussed and workarounds suggested on InValidLogic.com's article Serving Static Content Via POST From Nginx: in that case you could replace the error message with error_page 405 =200 $uri; or create a proxy for static content, converting POST request to GET.

However, in this case your /formcheck is actually a PHP script instead of static content, thus POST requests should be allowed by Nginx and there is POST data to be received, so converting to GET isn't an option, either.

It seems you have two location sections:

    location / {
        if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
            root home/$2/public_html;
            access_log  logs/$2-access.log  main;
        }
    }

    location ~ \.php$ {
        if ($host ~ ^(www\.)?([a-z0-9\-\.]+)$){
            root home/$2/public_html;
            access_log  logs/$2-access.log  main;
        }
        if (!-e $document_root$document_uri){return 404;}
        fastcgi_pass localhost:9071;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

As you can see, only locations ending with .php are handled with fastcgi, while everything else including /formcheck falls into location / serving only static content, causing the 405 error.

3
  • So... To fix this I should return to formcheck.php or put it in another directory with only .php files to apply the new rule to them all?
    – Telion
    Jun 7, 2017 at 14:10
  • 1
    ...or add a new matching location. :) Jun 7, 2017 at 14:20
  • The only problem is that there will be more files like this, so to make them all work I will need to define every single one in location? Or can you bring some basic example of location for this?
    – Telion
    Jun 7, 2017 at 14:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .