Nginx static file response to POST request prompt 405 Error Resolution _nginx

Source: Internet
Author: User
Tags curl nginx server

Example 1: Send a POST request to an HTML static page on the Apache server with the Curl command under Linux

Copy Code code 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>
The requested method POST is isn't 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: Using the Curl command under Linux to send post requests to the HTML static page on the Nginx server

Copy Code code as follows:

[Root@localhost ~]# curl-d 11=1 http://www.jb51.net/index.htm
<body bgcolor= "White" >
<center></body>

However, in some applications, it is necessary to enable static files to respond to post requests.
For Nginx, you can modify the nginc.conf configuration file, change the "405 error" to "OK" and configure the location to resolve the following methods:

Copy Code code 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 modify the Nginx source code to solve
Modify the source code, recompile the installation Nginx
Edit Nginx Source Code

Copy Code code as follows:

[Root@localhost ~]# Vim src/http/modules/ngx_http_static_module.c

Modify: Find the following comment out

Copy Code code as follows:

/*
if (R->method & Ngx_http_post)
{
return ngx_http_not_allowed;
}
*/

Then, according to the original compilation parameters, recompile installation nginx, you can

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.