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.zyan.cc/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.zyan.cc;
   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服务器 | 评论(44) | 引用(0) | 阅读(124013)
bighearted
2008-4-10 20:05
不错,空间速度今天很慢啊
张宴 回复于 2008-4-11 12:08
服务器的1M带宽被占满,现在已解决。
easylife
2008-4-17 08:08
帅哥,能否说说什么应用需要向静态页发送post请求。多谢。
小弟
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.
糖尿病足 Homepage
2012-3-12 15:28
我来看看博主
coach factory outlet Email Homepage
2012-5-17 11:27
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 11:27
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 11:27
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 11:27
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
xujie777 Email
2012-5-18 16:49
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
分页: 1/3 第一页 1 2 3 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]