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. C++设计模式-Visitor访问者模式

    #include <iostream> #include <string> #include <string.h> #include <memory> ...

  2. ubuntu 14.04安装postgresql最新版本

    官网:https://www.postgresql.org/download/linux/ubuntu/ ----------------------------------------------- ...

  3. 【dfs 回溯】 zoj 1004

    题意:给出一个源字符串和一个目标字符串,打出所有符合stack操作的i,o串使得对于源字符串的操作能变为目标字符串 思路:搜索,回溯. 之前想过是不是队列,觉得不对那样bfs是求最优解了:也想过用结构 ...

  4. C# 实现屏幕键盘 (ScreenKeyboard)

    原文地址:http://www.cnblogs.com/youzai/archive/2008/05/19/1202732.html 要实现一个屏幕键盘,需要监听所有键盘事件,无论窗体是否被激活.因此 ...

  5. 最短路<dijk>

    题意: 有n个城市,有m条路,给出每条路的出发和结束的城市及长度,求从第一个城市到最后一个城市的最短路.按格式输出. power oj 2443 题解: 标准dijk算法. #include<c ...

  6. 用 Swift 编写面向协议的网络请求

    和我一起参加9 月 1 日 - 9月 2 日在纽约举办的 Swift 社区庆典

  7. NSUserDefault -- synchronize 浅析

    NSUserDefault的使用比较简单:NSUserDefaults *mySettingData = [NSUserDefaults standardUserDefaults];  创建NSUse ...

  8. linker command failed with exit code 1 (use -v to see invocation)修改方法

    它的意思是指文件丢失或者文件重复,你就要仔细查看项目中有没有重复的文件,如有重复修改即可,如果是文件丢失,那就麻烦啦!你需要根据报错的地方进行修补文件,最为直接的方法是重新创建项目.还有另外一种情况是 ...

  9. IDL 计算TVDI

    介绍请看:http://blog.sina.com.cn/s/blog_764b1e9d0100wdrr.html 源码: IDL 源码PRO TVDI,NDVI,LST,NBINS,RES RES ...

  10. PAT (Advanced Level) 1101. Quick Sort (25)

    树状数组+离散化 #include<cstdio> #include<cstring> #include<cmath> #include<map> #i ...