Hi,
我用openresty(最新)做了一个IP过滤器:
server {
access_by_lua_file 'conf/check.lua';
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
}
check.lua:
----------------------
local shm = ngx.shared.blacklist
local source = ngx.req.get_headers() ["X-Forwarded-For"]
if source ~= nil then
for token in string.gmatch(source, "[^,]+") do
if shm:get (token) then
ngx.exit (403)
end
end
end
ngx.exit (ngx.OK)
结果所有的请求都变成空白了:
< HTTP/1.1 200 OK
* Server openresty is not blacklisted
< Server: openresty
< Date: Wed, 09 Jul 2014 02:11:43 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
很奇怪,这些php都没有执行,error.log也是空白
我用的是 ngx.OK 啊,如果是 HTTP_OK 才会停止处理请求吧