Nginx static file response POST request prompt 405 error Solution

Source: Internet
Author: User

Example 1: Use the curl command in linux to send a POST request to the HTML static page on the Apache server

Copy codeThe Code is as follows: [root @ localhost ~] # Curl-d 11 = 1 http://www.jb51.net/index.html
<! Doctype html public "-// IETF // dtd html 2.0 // EN">
<HTML>
<HEAD>
<TITLE> 405 Method Not Allowed </TITLE>
</HEAD>
<BODY>
<H1> Method Not Allowed </H1>
The requested method POST is not allowed for the URL/index.html. <P>
<HR>
<ADDRESS> Apache/1.3.37 Server at www.jb51.net Port 80 </ADDRESS>
</BODY>
</HTML>

Example 2: Use the curl command in linux to send a POST request to the HTML static page on the nginx Server

Copy codeThe Code is as follows: [root @ localhost ~] # Curl-d 11 = 1 http://www.jb51.net/index.htm
<Html>
<Head> <title> 405 Not Allowed </title> <Body bgcolor = "white">
<Center> <Hr> <center> nginx/1.2.0 </center>
</Body>
</Html>

However, in some applications, static files must be able to respond to POST requests.
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:

Copy codeThe Code is as follows: server
{
Listen 80;
Server_name www.jb51.net;
Index index.html index.htm index. php;
Root/opt/htdocs;
If (-d $ request_filename)
{
Rewrite ^/(. *) ([^/]) $ http: // $ host/$1 $2/permanent;
}
Error_page 405 = 200 @ 405;
Location @ 405
{
Root/opt/htdocs;
}
Location ~ . * \. Php? $
{
Include conf/fcgi. conf;
Fastcgi_pass 127.0.0.1: 10080;
Fastcgi_index index. php;
}
}

Of course, you can also modify the nginx source code to solve the problem.
Modify source code, recompile and install nginx
Edit nginx source code

Copy codeThe Code is as follows: [root @ localhost ~] # Vim src/http/modules/ngx_http_static_module.c

Modify: comment out the following section.

Copy codeThe Code is as follows :/*
If (r-> method & NGX_HTTP_POST)
{
Return NGX_HTTP_NOT_ALLOWED;
}
*/

Then, recompile and install nginx based on the original compilation parameters.

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.