大网数据广告活动
服务器运维问答

405 (Not Allowed) on POST request

· 52CE 我爱测

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 work…

问题原文

原帖链接 · Telion · CC BY-SA 4.0

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

已采纳解答

原帖链接 · Esa Jokinen · CC BY-SA 4.0

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.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。