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.