The Nginx static file responds to the POST request and prompts the error 405.

Source: Internet
Author: User

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@localhost ~]# curl -d 11=1 http://www.92csz.com/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.92csz.com 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

[root@localhost ~]# curl -d 11=1 http://www.92csz.com/index.htm   

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 www.92csz.com;       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

[root@localhost ~]# vim src/http/modules/ngx_http_static_module.c  

Modify: comment out the following section.

/*  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.