防恶意压测 限制同 ip 每秒不超过 20 个请求,nginx 配置: http { limit_req_zone $binary_remote_addr zone=shagon:10m rate=20r/s; server { limit_req zone=shagon burst=5 nodelay; …… } …… } http_load 返回 https://dujun.io: byte count wrong 2018-02-08
启用 http/2 server { listen 443 ssl http2; …… } 验证方法,chrome 输入: chrome://net-internals/#http2 2017-12-25
debian部署 个人环境部署 apt-get install sudo apt-get install vim vim /etc/sudoers #增加 shagon ALL=(ALL:ALL) NOPASSWD:ALL sudo vim /etc/vim/vimrc #去掉 syntax on 前的注释 set tabstop=4 set softtabstop=4 colorscheme desert vim /home/shagon/.ssh/authorized_keys #增加本地密钥 #安装 oh-my-zsh sudo apt-get install zsh sudo apt-get install git sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"... 2017-10-30
mysql 列值转换和统计 将 user_sample |uid|201608|201609|201610|201611| |张三|iPhone|mi|mi|Google| |李四|mi|mi|Google|Google| |王五|Google|mi|iPhone|iPhone| 转换为 phone_result |uid|iPhone|mi|Google| |张三|1|2|1| |李四|0|2|2| |王五|2|1|1| sql 如下: drop table if exists tmp; drop table if exists phone_result; create table tmp as select uid, `201608` as brand, `201608` as month from `user_sample`; insert into tmp select uid, `201609` as... 2017-09-13
62进制转换 //十进制转为 62 进制 function encode62($number) { $base = 62; $index = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $ret = ''; for ($t = floor(log10($number) / log10($base)); $t >= 0; $t--) { $a = floor($number / pow($base, $t)); $ret .= substr($index, $a, 1); $number -= $a * pow($base, $t); } return $ret; } //62 进制转为十进制 function decode62($number) { $base = 62; $index =... 2017-08-31
建站之天气获取 写文章时自动抓取当前天气,找了几个 api 都不靠谱,直接采集中国天气网的数据。 例如采集富阳的天气地址: $url = 'http://www.weather.com.cn/weather/101210108.shtml'; $raw = file_get_contents($url); $raw = str_replace("\n", '', $raw); if (preg_match('', $raw, $match)) { //匹配到天气文字 } 2017-05-26
建站之 redis 纯内存运行 mysql 做永久存储,redis 做缓存。所以将 redis 设置为纯内存运行,减少开销。 编辑 /etc/redis/redis.conf,修改下列几项 #注释掉 save 项 #save 900 1 #save 300 10 #save 60 10000 #设置最多 1G 内存 maxmemory 1GB maxmemory-policy volatile-lru appendfsync no 2017-05-19
建站之视频处理 借助 ffmpeg 扩展处理视频。包括自动旋转、截图、转换格式等。 ubuntu 下安装扩展 sudo apt-get install ffmpeg 获取视频尺寸、旋转角度 /** * /usr/bin/ffprobe video.mp4 -show_streams -print_format json */ public static function info($video) { $raw = shell_exec(sprintf('%s %s -show_streams -print_format json', self::ffprobe(), $video)); if (empty($raw) || !($raw = json_decode($raw, true)) || empty($raw['streams'])) { return false; } foreach... 2017-05-18