squid编译安装 web缓存服务器

19 篇文章 0 订阅
14 篇文章 0 订阅

先安装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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值