您的位置:首页 > 运维架构 > 反向代理

squid编译安装 web缓存服务器

2016-03-15 16:31 477 查看
先安装webp、jpeg、png等库

http://www.linuxfromscratch.org/blfs/view/svn/general/libwebp.html
先下载libwebp-0.3.0.tar.gz
tar -zxvf libwebp-0.3.0.tar.gz
cd libwebp-0.3.0
./configure && make && make install
cp /usr/local/lib/libwebp.so.4.0.2/usr/lib64/
ln -s /usr/lib64/libwebp.so.4.0.2/usr/lib64/libwebp.so.4
ln -s /usr/lib64/libwebp.so.4.0.2/usr/lib64/libwebp.so


安装graphicsmagick

下载http://sourceforge.net/projects/graphicsmagick/files/
解压后进入
./configure  --prefix=/usr/local/webserver/GM_webp --with-webp
./configure --prefix=/usr/local/webserver/GM_new --with-webp --with-jpeg=/usr/local/webserver/jpeg9/ --with-png=/usr/local/webserver/png/ --enable-shared
make
make install装图](https://img-blog.csdn.net/20160315162713528)


gmagick安装

下载http://pecl.php.net/package/gmagick
解压进入源码包
wget http://pecl.php.net/get/gmagick-1.1.5RC1.tgz /usr/local/webserver/php/bin/phpize
./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-gmagick=/usr/local/webserver/graphicsmagick/
make
make install


nginx简单配置

location ~* ([0-9a-z\/]+)/([0-9a-z]+).(jpg|png|bmp|gif)_([0-9]+)x([0-9]+)(.*)$ {
#default_type text/html;
root  /data/filesystem/thumbnail/;
set $image_root /data/filesystem/;
set $thumbnail_root /data/filesystem/thumbnail/;
set $ways $1;
set $fileName $2.$3;
set $width  $4;
set $height $5;
set $origin  $image_root$ways/$fileName;
set $file  $thumbnail_root$uri;
set $dir $thumbnail_root$ways;
set $quality $6;
if (!-f $file) {
rewrite_by_lua '
local command1 = "mkdir -p " .. ngx.var.dir
local quality = string.sub(ngx.var.quality,2,3)
if quality ~= nil and quality ~= "jp" and quality ~= "pn" and quality ~= "bm" and quality ~= "gi" then
local command2 = "/usr/local/webserver/GM/bin/gm convert -quality " .. quality .. " " .. ngx.var.origin .. " -thumbnail " .. ngx.var.width .. "x" .. ngx.var.height .. " " .. ngx.var.file
os.execute(command1)
os.execute(command2)
else
local command2 = "/usr/local/webserver/GM/bin/gm convert " .. ngx.var.origin .. " -thumbnail " .. ngx.var.width .. "x" .. ngx.var.height .. " " .. ngx.var.file
os.execute(command1)
os.execute(command2)
end
';
}

}


访问原图http://file0.10000.com/1.jpg

访问截图http://file0.10000.com/1_300x300.jpg

压缩质量http://file0.10000.com/1.JPG_270x270_50.jpg
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  web