Apache、IIS、Nginx等绝大多数web服务器,都不允许静态文件响应POST请求,否则会返回“HTTP/1.1 405 Method not allowed”错误。

  例1:用Linux下的curl命令发送POST请求给Apache服务器上的HTML静态页
[root@new-host ~]# curl -d 1=1 http://www.sohu.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.sohu.com Port 80</ADDRESS>
</BODY></HTML>


  例2:用Linux下的curl命令发送POST请求给Nginx服务器上的HTML静态页
[root@new-host ~]# curl -d 1=1 http://blog.s135.com/tech/index.htm
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<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  domain.s135.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;
   }
}



Tags: , ,
技术大类 » Web服务器 | 评论(13) | 引用(0) | 阅读(24784)
bighearted
2008-4-10 20:05
不错,空间速度今天很慢啊
张宴 回复于 2008-4-11 12:08
服务器的1M带宽被占满,现在已解决。
easylife
2008-4-17 08:08
帅哥,能否说说什么应用需要向静态页发送post请求。多谢。
仙后
2008-7-22 21:39
zan
小弟
2008-12-9 17:58
张老师请问你BLOG租用的那个服务器是哪个提供商的啊 我也想去租一个 虚拟机的把
reibill
2009-2-19 13:12
张老师,您好,我按照你的配置,修改了nginx.conf,用nginx -t测试了配置文件,没有语法错误,但是,我用curl进行测试的时候,还是报告405错误,似乎并没有重定向成功,配置和您的一样,就是root那里改了。
  error_page   405 =200 @405;
  location @405
  {
      root  /home/nemo/htdocs;
  }
在access.log里面依旧显示405,我有重启过nginx的程序。
hi
2009-5-27 14:33
按照这个配置还是一样提示405错误
hello
2009-7-29 08:59
这个方法没效果,依旧是405错误
psit
2010-4-26 17:03
看看
峻泽
2010-7-27 21:05
这个方法不行啊!!还是405 Not Allowed!!!
OUYANG
2011-6-7 16:21
不行呀
btweng
2011-7-6 15:49
编辑nginx源代码
[root@new-host ~]# vim src/http/modules/ngx_http_static_module.c
修改: 找到下面一段注释掉
/*if (r->method & NGX_HTTP_POST) {
        return NGX_HTTP_NOT_ALLOWED;
       }*/
然后按照原来的编译参数,重新编译安装nginx,即可
cnrainbing Email
2011-9-8 17:48
张老师很给力啊支持
louis vuitton uk Email Homepage
2011-11-23 08:59
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]