欢迎来到梦飞科技

服务器租用

当前优惠活动:

Nginx处事器情况POST请求静态文件返回405错误的问题

Apache、IIS、Nginx等绝大大都web处事器,都不答允静态文件响应POST请求香港服务器 香港服务器租用,不然会返回“HTTP/1.1 405 Method not allowed”错误。

  例1:用Linux下的curl呼吁发送POST请求给Apache处事器上的HTML静态

[[email protected] ~]# curl -d 1=1 http://www.server110.com/

<!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.server110.com Port 80</ADDRESS>

</BODY></HTML>

  例2:用Linux下的curl呼吁发送POST请求给Nginx处事器上的HTML静态页

[[email protected] ~]# curl -d 1=1 http://www.server110.com/

<html>

<head><title>405 Not Allowed</title></head>

<body >

<center><h1>405 Not Allowed</h1></center>

<hr><center>nginx/0.5.35</center>

</body>

</html>

  但在有些应用中,需要使静态文件可以或许响应POST请求。

  对付Nginx,可以修改nginc.conf设置文件,改变“405错误”为“200 ok”,并设置location来办理,要领如下:

server

{

   listen       80;

   server_name  www.server110.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;

   }

}

####################################### 修改源代码,从头编译安装nginx

编辑nginx源代码

[[email protected] ~]# vim src/http/modules/ngx_http_static_module.c

修改: 找到下面一段注释掉

/*if (r->method & NGX_HTTP_POST) {
        return NGX_HTTP_NOT_ALLOWED;
       }*/

然后凭据本来的编译参数,从头编译安装nginx,即可

梦飞科技 - 全球数据中心基础服务领先供应商

Copyright © 2003-2019 MFISP.COM. 国外服务器租用 IDC公司 版权所有 粤ICP备11019662号