Solve the problem of "HTTP/1.1 405 method not allowed" and let the static file respond to the POST request [original]

Source: Internet
Author: User
Tags nginx server

The vast majority of web servers such as Apache, IIS, and nginx do not allow static files to respond to post requests. Otherwise, an "HTTP/1.1 405 method not allowed" error will be returned.

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

[Root @ New-host ~] # Curl-D 1 = 1 http://www.sohu.com/index.HTML
<! Doctype HTML public "-// IETF // dtd html 2.0 // en">
<HTML> <Title> 405 method not allowed </title>
</Head> <body>
<H1> method not allowed The requested method post is not allowed for the URL/index. html. <p>
<HR>
<Address> Apache/1.3.37 server at www.sohu.com port 80 </address>
</Body> Example 2: Use the curl command in Linux to send a POST request to the HTML static page on the nginx Server

[Root @ New-host ~] # Curl-D 1 = 1 http://blog.s135.com/tech/index.htm
<HTML>
<Head> <title> 405 not allowed </title> <Body bgcolor = "white">
<Center> <HR> <center> nginx/0.5.35 </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:

Server
{
Listen 80;
SERVER_NAME domain.s135.com;
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;
}
}

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.