一 16
Nginx + Lua + Redis
redis_parser = require "redis.parser"
function redis_query(reqs)
local raw_reqs = {}
for i, req in ipairs(reqs) do
table.insert(raw_reqs, redis_parser.build_query(req))
end
local res = ngx.location.capture("/redis2?" .. #reqs, { body = table.concat(raw_reqs, "") })
if res.status ~= 200 or not res.body then
ngx.log(ngx.ERR, "failed to query redis")
ngx.exit(500)
end
return redis_parser.parse_replies(res.body,#reqs)
end
local query = {
{"srandmember","oncity:iknow"},
{"hincrby","counter:domain:"..ngx.today(),"all",1},
}
local url = ngx.var.http_referer
if url~=nil then
url = string.lower(url)
local md5_key = ngx.md5(url)
table.insert(query, {"zincrby","counter:top",1,md5_key} )
table.insert(query, {"hsetnx","counter:url",md5_key,url} )
local m = ngx.re.match(url, "^http://(\\w+).oncity","i")
if m ~= nil then
table.insert(query,{"hincrby","counter:domain:"..ngx.today(),m[1],1})
end
end
local replies = redis_query(query)
ngx.say("document.write('",replies[1][1],"');")
五 22
varnish 比起 squid 优越的地方实在太多,配置文件也简单直接,很适合图片分流,自建 CDN 等应用.
在 Ubuntu 下安装也很简单.
奇怪的是使用 -s file 方式,运行一段时间后 (2个小时左右)就会自动不断重起进程!
分享一段启动配置给大家,能相对稳定多.
DAEMON_OPTS=”-a :80 \
-T localhost:6082 \
-f /etc/varnish/oc.vcl \
-p thread_pool_min=200 -p thread_pool_max=4000 -p thread_pools=4 -p thread_pool_add_delay=2 -p listen_depth=4
096 -p session_linger=50/100/150 -p lru_interval=20 -h classic,500009 -s malloc,2G”
五 22
第一招,傻瓜式
优点: 简单
不足之处: 只能防普通页面盗链
valid_referers none blocked *.foo.com;
if ($invalid_referer) {
return 403;
}
第二招进阶式 通过 nginx-accesskey 增强
优点: 针对不同的IP访问成生不同的 Key 相对安全
不足之处: 只要是同IP , Key 就会相同…形成虚设
location /mp3/ {
alias /www/mp3/;
accesskey on;
accesskey_hashmethod md5;
accesskey_arg "key";
accesskey_signature "yourpasswd$remote_addr";
}
第三招复杂进阶式 nginx-accesskey + url + 网站页面登陆控制
优点: 加入 url 作生成 Key ,相对安全
如果能设定过期时间就更好了.
location /mp3/ {
alias /www/mp3/;
accesskey on;
accesskey_hashmethod md5;
accesskey_arg "key";
accesskey_signature "yourpasswd$remote_addr$uri";
limit_conn one 1;
limit_rate 16k;
}
五 17
批量改名 gif 版
#!/bin/bash
n=0;
for file in `ls *.gif`; do
let n+ +;
echo $file to $n.gif;
mv $file $n.gif;
done;
cat a.url | while read i;do grep $i d.url; done
四 10
中国的网民就是这样老实,10年不变坚持用XP + IE6
其实升级一下有多难?这是微软的成功?还是失败?
四 10
forum_ids = unserialize($_DPLUGIN['oncity']['vars']['shop_forum_ids']);
$this->open_forum_ids = unserialize($_DPLUGIN['oncity']['vars']['s_pic_open_forum_ids']);
if(!@include DISCUZ_ROOT.'./forumdata/cache/cache_oncity.php') {
$_SHOP_IDS = $this->_oncity_updateCache();
}
$this->_SHOP_IDS = $_SHOP_IDS;
}
function _oncity_updateCache() {
global $db, $tablepre;
$shop_ids = array();
$query = $db->query("SELECT uid from {$tablepre}members WHERE groupid=24");
while($sub = $db->fetch_array($query)) {
$shop_ids[]=$sub['uid'];
}
include_once DISCUZ_ROOT.'./include/cache.func.php';
writetocache('oncity', '', getcachevars(array('_SHOP_IDS' => $shop_ids)));
return $shop_ids;
}
}