暂做笔记,带后续验证通过后,再补充 1、2、3 步。

一、安装 lua

首先确认是否安装 readline

  1. yum -y install readline-devel ncurses-devel

进入页面:http://www.lua.org/download.html

  1. wget http://www.lua.org/ftp/lua-5.3.1.tar.gz
  2.  
  3. tar zxvf lua-5.3..tar.gz
  4.  
  5. #进入解压目录
  6. make linux && make install
  1. wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
  2. tar zxvf LuaJIT-2.0..tar.gz
  3. cd LuaJIT-2.0.
  4. make && make install
  1. ln -s /usr/local/lib/libluajit-5.1.so. /lib64/libluajit-5.1.so.
  2. export LUAJIT_LIB=/usr/local/lib
  3. export LUAJIT_INC=/usr/local/include/luajit-2.0/

二、安装 GraphicsMagick

进入页面:http://www.graphicsmagick.org/1.3/download.html

  1. tar zxvf GraphicsMagick-1.3..tar.gz
  2. cd GraphicsMagick-1.3.
  3. ./configure --prefix=/usr/local/graphicsmagick
    make && make install
  4.  
  5. #验证

/usr/local/graphicsmagick/bin/gm version

三、安装nginx

进入页面:http://tengine.taobao.org/opensource_cn.html

  1. ./configure --prefix=/usr/local/nginx \
  2. --dso-path=/usr/local/nginx/modules \
  3. --with-http_realip_module \
  4. --with-http_gzip_static_module \
  5. --with-http_stub_status_module \
  6. --with-http_concat_module \
  7. --with-http_lua_module \
  8. --with-pcre=/usr/local/src/pcre-8.37\
  9. --with-zlib=/usr/local/src/zlib-1.2.\
  10. --with-openssl=/usr/local/src/openssl-1.0.0s\
  11. --http-proxy-temp-path=/var/tmp/nginx/proxy_temp \
  12. --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp \
  13. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp \
  14. --http-scgi-temp-path=/var/tmp/nginx/cgi_temp \
  15. --http-client-body-temp-path=/var/tmp/nginx/client_body_temp \
  16. --http-log-path=/var/log/nginx/access.log \
  17. --error-log-path=/var/log/nginx/error.log\
  18. --with-ld-opt="-Wl,-rpath,$LUAJIT_LIB"
  19.  
  20. make && make install
  21.  
  22. #启动nginx
  23. #测试配置文件
  24. /usr/local/nginx/sbin/nginx -t
  25.  
  26. #启动
  27. /usr/local/nginx/sbin/nginx

设置开机启动

  1. vi /etc/rc.d/init.d/nginx
  1. #!/bin/bash
  2. # Tengine Startup script# processname: nginx
  3. # chkconfig: -
  4. # description: nginx is a World Wide Web server. It is used to serve
  5. # pidfile: /var/run/nginx.pid
  6. # config: /usr/local/nginx/conf/nginx.conf
  7. nginxd=/usr/local/nginx/sbin/nginx
  8. nginx_config=/usr/local/nginx/conf/nginx.conf
  9. nginx_pid=/usr/local/nginx/logs/nginx.pid
  10. RETVAL=
  11. prog="nginx"
  12. # Source function library.
  13. . /etc/rc.d/init.d/functions
  14. # Source networking configuration.
  15. . /etc/sysconfig/network
  16. # Check that networking is up.
  17. [ ${NETWORKING} = "no" ] && exit
  18. [ -x $nginxd ] || exit
  19. # Start nginx daemons functions.
  20. start() {
  21. if [ -e $nginx_pid ];then
  22. echo "tengine already running...."
  23. exit
  24. fi
  25. echo -n $"Starting $prog: "
  26. daemon $nginxd -c ${nginx_config}
  27. RETVAL=$?
  28. echo
  29. [ $RETVAL = ] && touch /var/lock/subsys/nginx
  30. return $RETVAL
  31. }
  32. # Stop nginx daemons functions.
  33. stop() {
  34. echo -n $"Stopping $prog: "
  35. killproc $nginxd
  36. RETVAL=$?
  37. echo
  38. [ $RETVAL = ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
  39. }
  40. reload() {
  41. echo -n $"Reloading $prog: "
  42. #kill -HUP `cat ${nginx_pid}`
  43. killproc $nginxd -HUP
  44. RETVAL=$?
  45. echo
  46. }
  47. # See how we were called.
  48. case "$1" in
  49. start)
  50. start
  51. ;;
  52. stop)
  53. stop
  54. ;;
  55. reload)
  56. reload
  57. ;;
  58. restart)
  59. stop
  60. start
  61. ;;
  62.  
  63. status)
  64. status $prog
  65. RETVAL=$?
  66. ;;
  67. *)
  68. echo $"Usage: $prog {start|stop|restart|reload|status|help}"
  69. exit
  70. esac
  71. exit $RETVAL

保存退出

  1. chmod /etc/rc.d/init.d/nginx #赋予文件执行权限
  2. chkconfig --level nginx on #设置开机启动
  3. service nginx start

四、配置 nginx

nginx.conf

  1. http
  2. {
  3. lua_package_path '/usr/local/openresty/nginx/lua/?.lua;;';
  4.  
  5. server {
  6. listen ;
  7. server_name img.rhythmk.org;
  8. root /home/wwwroot/static/image;
  9.  
  10. #对类似_100x100.gif/jpg/png/jpeg进行缩略图处理
  11. location ~* _([-]+)x([-]+)\.(gif|jpg|png|jpeg)$ { #匹配文件名规则
  12. root /home/wwwroot/static/image; #站点根目录
  13. set $image_root /home/wwwroot/static/image; #图片目录
  14. set $thumbnail_root /home/wwwroot/static/thumbnail; #缩略图存放目录
  15. #如果缩略图文件存在,直接返回
  16. set $file $thumbnail_root$uri;
  17. if (-f $file) {
  18. rewrite ^/(.*)$ /thumbnail/$ last;
  19. }
  20. #如果缩略图文件不存在,则应用缩略图模块处理
  21. if (!-f $file) {
  22. rewrite_by_lua_file lua/thumbnail.lua;
  23. }
  24. }
  25. }
  26.  
  27. #include conf/*.conf;
  28. }

lua/thumbnail.lua

  1. local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)");
  2. local originalUri = string.sub(ngx.var.uri, , index-);
  3. local area = string.sub(ngx.var.uri, index);
  4. index = string.find(area, "([.])");
  5. area = string.sub(area, , index-);
  6.  
  7. local image_sizes = {"80x80", "800x600", "40x40"};
  8. function table.contains(table, element)
  9. for _, value in pairs(table) do
  10. if value == element then
  11. return true
  12. end
  13. end
  14. return false
  15. end
  16.  
  17. if table.contains(image_sizes, area) then
  18. local command = "gm convert " .. ngx.var.image_root .. originalUri .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .. " " .. ngx.var.file;
  19. os.execute(command);
  20. ngx.req.set_uri(ngx.var.uri, true);
  21. else
  22. ngx.exit();
  23. end;

nginx+lua_nginx+GraphicsMagick生成实时缩略图的更多相关文章

  1. Nginx+lua_Nginx+GraphicsMagick来实现实时缩略图

    1.安装GraphicsMagick cd /usr/local/src wget http://sourceforge.net/projects/graphicsmagick/files/graph ...

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

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

  3. c#.net 生成清晰缩略图

    1 public void imgsize() 2 { 3 //本例中假定了两个变量: 4 5 String src = "c:/myImages/a.jpg"; //源图像文件的 ...

  4. ASP.NET根据URL生成网页缩略图示例程序(C#语言)

    工作中可能马上要用到根据URL生成网页缩略图功能,提前做好准备. 在网上找了份源码,但是有错误:当前线程不在单线程单元中,因此无法实例化 ActiveX 控件“8856f961-340a-11d0-a ...

  5. 利用FFmpeg生成视频缩略图 2.3.1

    1.下载FFmpeg文件包,解压包里的\bin\下的文件解压到 D:\ffmpeg\ 目录下. 下载地址 http://ffmpeg.zeranoe.com/builds/win32/static/ ...

  6. 利用FFmpeg生成视频缩略图 2.1.8

    1.下载FFmpeg文件包,解压包里的\bin\下的文件解压到 D:\ffmpeg\ 目录下. 下载地址 http://ffmpeg.zeranoe.com/builds/win32/static/ ...

  7. 利用FFmpeg生成视频缩略图 2.1.6

    利用FFmpeg生成视频缩略图 1.下载FFmpeg文件包,解压包里的\bin\下的文件解压到 D:\ffmpeg\ 目录下. 下载地址 http://ffmpeg.zeranoe.com/build ...

  8. PHP一般情况下生成的缩略图都比较不理想

    PHP用GD库生成高质量的缩略图片,PHP一般情况下生成的缩略图都比较不理想.今天试用PHP,GD库来生成缩略图.虽然并不100%完美.可是也应该可以满足缩略图的要求了.<?php $FILEN ...

  9. NGINX按天生成日志文件的简易配置

    NGINX按天生成日志文件的简易配置 0x01 最近后端童鞋遇到一个小需求,拆分nginx生成的log文件,最好是按天生成,看着她还有很多bug待改的状态,我说这个简单啊,我来吧.曾经搞node后端的 ...

随机推荐

  1. [C++] C/C++ 取整函数ceil(),floor()

    使用floor函数.floor(x)返回的是小于或等于x的最大整数.如:     floor(10.5) == 10    floor(-10.5) == -11 使用ceil函数.ceil(x)返回 ...

  2. [游戏学习22] MFC 井字棋 双人对战

    >_<:太多啦,感觉用英语说的太慢啦,没想到一年做的东西竟然这么多.....接下来要加速啦! >_<:注意这里必须用MFC和前面的Win32不一样啦! >_<:这也 ...

  3. jquery 判断手势滑动方向(上下左右)

    $('body').on('click', '.placeholder img', function(e) { //touchstart在你之前发生,不管些什么,都先执行下面的 }); $('body ...

  4. paip.Log4j配置不起作用的解决

    paip.Log4j配置不起作用的解决 1.jar包里的log4j配置 看累挂jar,真的有个" webservices-rt.jar\com\sun\org\apache\xml\inte ...

  5. SAFS Init Files

    There're many deployment files for configuration. We need to learn how SAFS read these depolyment fi ...

  6. Cause for NullPointerException android.support.v7.widget.RecyclerView.onMeasure

    because you have not set LinearLayoutManager to RecyclerView. for example: mRecyclerView = (Recycler ...

  7. c#之第一课入门

    这几天看到微软的build大会,感觉微软不甘落后他人,曾经的巨头难道又要重新崛起,不管了,为了以后的饭碗,还是简单学习一些c#吧,有时这种紧张感不错的,现在由于这种紧张感,我已经掌握的java(主要弄 ...

  8. ios之VFL的补充(二)

    [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[languageI ...

  9. 采用TL026等构成的宽带ALC放大器电路图

    Building a Differential Amplifier An op-amp with no feedback is already a differential amplifier, am ...

  10. Spring和cxf3的整合,以maven的方式

    一.引入cxf3 我这里使用的是最新的版本cxf3.1.8 引入cxf3需要在pom.xml加入如下内容: <dependency> <groupId>org.apache.c ...