在Apache中,配置只允许GET请求的设置
当有POST请求时,不会被记录在web服务器的日志中,是不是很讨厌?
当有POST请求时,将会进行拦截处理。
使用Apache的LimitExcept指令来实现。(http://httpd.apache.org/docs/2.4/ja/mod/core.html#limitexcept)
网页服务器的设置
Alias /get_only/ /usr/home/qoAop/public_html/get_only/
<Directory "/usr/home/qoAop/public_html/get_only/">
Options ExecCGI FollowSymLinks Includes
AllowOverride None
AddHandler cgi-script .cgi
<LimitExcept GET>
Order deny,allow
Deny from all
</LimitExcept>
</Directory>
示例程式
#!/usr/bin/perl
use strict;
my $env = $ENV{'REQUEST_METHOD'};
print <<EOM;
Content-Type: text/plain; charset=UTF-8
REQUEST_METHOD=$env
EOM
exit(0);
1;
确认动作
使用 wget 命令并携带 –post-data 参数,可以发送 POST 请求来进行确认。
成功访问,状态码为200 OK。
sh-3.2$ wget -S --no-proxy -O - http://127.0.0.1/get_only/method.cgi
--2015-03-23 18:21:54-- http://127.0.0.1/get_only/method.cgi
127.0.0.1:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています...
HTTP/1.1 200 OK
Date: Mon, 23 Mar 2015 09:21:54 GMT
Server: Apache
Connection: close
Content-Type: text/plain; charset=UTF-8
長さ: 特定できません [text/plain]
`STDOUT' に保存中
[<=> ] 0 --.-K/s REQUEST_METHOD=GET
[ <=> ] 19 --.-K/s 時間 0s
2015-03-23 18:21:54 (1.65 MB/s) - `-' へ保存終了 [19]
我收到了403 Forbidden的错误。
sh-3.2$ wget -S --no-proxy -O - --post-data "a=b" http://127.0.0.1/get_only/method.cgi
--2015-03-23 18:22:10-- http://127.0.0.1/get_only/method.cgi
127.0.0.1:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています...
HTTP/1.1 403 Forbidden
Date: Mon, 23 Mar 2015 09:22:10 GMT
Server: Apache
Content-Length: 221
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
2015-03-23 18:22:10 エラー 403: Forbidden。```
日志
127.0.0.1 - - [23/Mar/2015:18:21:54 +0900] "GET /get_only/method.cgi HTTP/1.0" 200 19 "-" "Wget/1.11.4 Red Hat modified" "-" 0 5958
127.0.0.1 - - [23/Mar/2015:18:22:10 +0900] "POST /get_only/method.cgi HTTP/1.0" 403 221 "-" "Wget/1.11.4 Red Hat modified" "-" 0 352