Nginx HTTP Post Method: 405 Method not allowed error

Source: Internet
Author: User
Tags http post

I recently maintained a RedHat 5.4 X64 system. The environment is Nginx. When running a forum, I need to submit POST data to the HTML page. All the results are intercepted and an error is displayed: "nginx 405 Not Allowed" is almost no good solution. The only thing we can do is recompile the Nginx source code and edit the conf file.

Later I learned that most web servers such as Apache, IIS, and Nginx do not allow static files to respond to POST requests. Otherwise"HTTP/1.1 405

Method not allowed "error

You need to modify the C source code file in Nginx to the/nginx source code directory/src/http/modules/ngx_http_static_module.c. Find the following code:

The code is as follows: Copy code

If (r-> method & NGX_HTTP_POST ){
Return NGX_HTTP_NOT_ALLOWED;
}

Comment out the following:

/* If (r-> method & NGX_HTTP_POST ){
Return NGX_HTTP_NOT_ALLOWED;
}
*/

Then re-compile make
Copy nginx under/nginx source code directory/objs directory to the installed Nginx directory, and restart Nginx to take effect.

For Nginx, you can modify the nginc. conf configuration file, change "405 error" to "200 OK", and configure location to solve the problem as follows:

The code is as follows: Copy code
Server
{  
Listen 80;
Server_name www.111cn.net;
Index index.html index.htm index. php;
Root/data/kiccleaf;
   
If ($ host! = 'Www .111cn.net '){
Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent;
    }
Location ~ . *. (Php | php5 )? $
    {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude GI. conf;
    }
# Add the following code 405
Error_page 405 = 200 @ 405;
Location @ 405
    {  
Root/data/kiccleaf;
    }  
}

You can also simply write it

The code is as follows: Copy code

Server
{  
Listen 80;
Server_name www.111cn.net;
Index index.html index.htm index. php;
Root/data/kiccleaf;
   
If ($ host! = 'Www .111cn.net '){
Rewrite ^/(. *) $ http://www.111cn.net/#1 permanent;
    }
Location ~ . *. (Php | php5 )? $
    {
Fastcgi_pass 127.0.0.1: 9000;
Fastcgi_index index. php;
Fcinclude GI. conf;
    }
# Add the following code 405
Error_page 405 = 200 $ uri;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.