nginx  编译的时候增加  ./configure --with-http_image_filter_module

配置如下

server

{

listen     80;

server_name 192.168.0.156;

index index.html index.htm index.php;

root /opt/htdocs;

access_log /opt/local/nginx/logs/access.log main;

location ~* (.*)/(\d+)\.(jpg|png|gif)$

{

set $h $arg_h;

set $w $arg_w;

#image_filter crop $h $w;

image_filter resize $h $w;

}

location ~* /(\d+)_(\d+)x(\d+)\.(jpg|png|gif)$

{

if ( -e $document_root/$1.$4 )

{

rewrite /(\d+)_(\d+)x(\d+)\.(jpg|png|gif)$ /$1.$4?h=$2&w=$3 last;

}

return 404;

}

}

缩略图使用.. 图片保存在 /opt/htdocs/upload/ 目录下面.. 如 0.jpg

原图访问 http://192.168.0.156/upload/0.jpg

缩略100x100 访问  http://192.168.0.156/upload/0_100x100.jpg

缩略300x300 访问  http://192.168.0.156/upload/0_300x300.jpg

如果原图不存在  将会返回 404 !!

生成缩略图到本地硬盘中

server

{

listen     80;

server_name 192.168.0.156;

index index.html index.htm index.php;

root /opt/htdocs;

access_log /opt/local/nginx/logs/www.xxx.com.log main;

location ~* ^/resize

{

set $width  100;

set $height 100;

set $dimens "";

if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" )

{

set $width $1;

set $height $2;

set $image_path $3;

set $demins "_$1x$2";

}

if ($uri ~* "^/resize/(.*)" )

{

set $image_path $1;

}

set $image_uri image_resize/$image_path?width=$width&height=$height;

if (!-f $request_filename) {

proxy_pass http://192.168.0.156/$image_uri;

break;

}

proxy_store /opt/htdocs/upload/resize$demins/$image_path;

proxy_store_access user:rw group:rw all:r;

proxy_set_header Host $host;

expires      30d;

access_log off;

}

location /image_resize {

alias /opt/htdocs/;

image_filter resize $arg_width $arg_height;

image_filter_jpeg_quality 75;

access_log off;

}

}

缩略图使用.. 图片保存在 /opt/htdocs/upload/ 目录下面.. 如 0.jpg

原图访问 http://192.168.0.156/upload/0.jpg

访问 http://192.168.0.56/resize/upload/0.jpg

location ~* ^/resize

{

set $width  100;

set $height 100;

set $dimens "";

缩略为定义的 100 x 100

当缩略图存在时间

访问  http://192.168.0.156/resize_100x100/upload/0.jpg

if ($uri ~* "^/resize_(\d+)x(\d+)/(.*)" )

{

set $width $1;

set $height $2;

set $image_path $3;

set $demins "_$1x$2";

}

if ($uri ~* "^/resize/(.*)" )

{

set $image_path $1;

}

缩略为 resize_$width x $height    缩略定义大小

当缩略图不存在时,使用直接缩略 图片质量为 75%

set $image_uri image_resize/$image_path?width=$width&height=$height;

location /image_resize {

alias /opt/htdocs/;

image_filter resize $arg_width $arg_height;

image_filter_jpeg_quality 75;

access_log off;

访问  http://192.168.0.156/image_resize/upload/0.jpg?width=100&height=100

并利用 Nginx proxy_store 缓存缩略的图片到本地

if (!-f $request_filename) {

proxy_pass http://192.168.0.156/$image_uri;

break;

}

proxy_store /opt/htdocs/upload/resize$demins/$image_path;

proxy_store_access user:rw group:rw all:r;

proxy_set_header Host $host;

expires      30d;

access_log off;

}

访问  http://192.168.0.156/resize_100x100/upload/0.jpg

生成图片的路径为 /opt/htdocs/upload/resize_100x100/upload/0.jpg

nginx 生成 缩略图 and 生成缩略图到硬盘的更多相关文章

  1. nginx实现本地图片生成缩略图

    nginx可以实现图片的缩略图效果,很多网站为了前端静态资源相应的性能会给大图自动生成一个小图,比如我们经常会在网上看到bd_64x64.png这种格式,淘宝上的小图经常会看到xxx.jpg_100x ...

  2. 转: nginx使用image_filter生成缩略图 -- fasdfs海量图片缩略图整合

      转: nginx使用image_filter生成缩略图 -- fasdfs海量图片缩略图整合 http://blog.csdn.net/CleverCode/article/details/522 ...

  3. 如何安装nginx_lua_module模块,升级nginx,nginx-lua-fastdfs-GraphicsMagick动态生成缩略图,实现图片自动裁剪缩放

    如何安装nginx_lua_module模块,升级nginx,nginx-lua-fastdfs-GraphicsMagick动态生成缩略图,实现图片自动裁剪缩放 参考网站:nginx-lua-fas ...

  4. 帝国cms教程:帝国cms在列表页使用sys_ResizeImg函数自动生成不同大小的缩略图

    先说说 ecms7.0的sys_ResizeImg这个函数 下面是在列表页使用方法 在右侧把使用程序代码打勾! 如下图: 例如你原先的列表页循环内容代码为: <li><img src ...

  5. Docker 实战(二)——centos7镜像安装nginx,将安装nginx的centos容器生成新的镜像,并导出

    Docker centos7镜像安装nginx 1.安装docker 使用yum安装docker不再重复:见  Linux常用命令 2.pull centos 1)在docker仓库中搜索centos ...

  6. nginx负载均衡、nginx ssl原理及生成密钥对、nginx配制ssl

    1.nginx负载均衡 新建一个文件:vim /usr/local/nginx/conf/vhost/load.conf写入: upstream abc_com{ip_hash;server 61.1 ...

  7. Nginx之 Location 的生成

    1. Location 的生成 location 的生成大致有三种: 由 location 指令直接生成 命令 location:仅用于 server 内部跳转,如 rewrite 就是命名 loca ...

  8. 代码文档生成工具-Doxygen生成CHM和RTF图文教程

    Doxygen是一种开源跨平台的,以类似JavaDoc风格描述的文档系统,可以从一套归档源文件开始,生成chm格式的文档.本文主要讲解如何在winddows下安装doxygen.     1.下载do ...

  9. Django 反向生成 从数据库生成Model

    Django 反向生成 从数据库生成Model 使用Django生成Model python manage.py inspectdb或python manage.py inspectdb > m ...

  10. uiautomatorviewer 优化定位符生成,支持生成Java,Python自动化代码

    项目介绍 二次开发 uiautomatorviewer 优化定位符生成,支持生成Java,Python自动化代码,修复自带工具画面有动态加载时截图失败问题,优化自带工具截图速度 ,实现类似录制脚本功能 ...

随机推荐

  1. EXP AND IMP

    purpors: exp pro data to uat data exp and imp will not create user expdp and impdp will create user ...

  2. php多进程实现

    php多进程实现 PHP有一组进程控制函数(编译时需要–enable-pcntl与posix扩展),使得php能在nginx系统中实现跟c一样的创建子进程.使用exec函数执行程序.处理信号等功能. ...

  3. hack,不同的IE浏览器

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  4. vmware卸载问题

    1. VMware版本问题:http://www.wuji8.com/meta/15866846.html2. VMware卸载问题:http://www.veryhuo.com/a/view/716 ...

  5. CodeForces 689C Mike and Chocolate Thieves (二分最大化最小值)

    题目并不难,就是比赛的时候没敢去二分,也算是一个告诫,应该敢于思考…… #include<stdio.h> #include<iostream> using namespace ...

  6. Node.js学习 - Install and Configure

    平台:Windows 官网:https://nodejs.org/en/ 下载安装 CMD中运行 1 交互模式 2 命令模式 模块安装 - NPM npm install express #当前目录安 ...

  7. Code Blocks 使用 VC2013编译HelloWord

    首先在 Settings-Complier中把 Microsoft Visual c++ 2010 设置成默认(莫不默认也无所谓,就是改着方便而已) 然后在ToolChain excutable 中, ...

  8. 1.2 selenium IDE录制脚本

    1.打开Firefox浏览器中 selenium IDE

  9. 1.3 selenium IDE录制脚本转换为其他代码格式

    1.在seleniumIDE录制框中点击Options->options... 在Enable experimental features前打对勾,点击确定.

  10. 洛谷U4727 小L 的二叉树

    U4727 小L 的二叉树 题目背景 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣. 所以,小L当时卡在了二叉树. 题目描述 在计算机科学中,二叉树 ...