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

一、安装 lua

首先确认是否安装 readline

  yum -y install readline-devel ncurses-devel

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

wget http://www.lua.org/ftp/lua-5.3.1.tar.gz  

tar zxvf lua-5.3..tar.gz 

#进入解压目录
make linux && make install
wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar zxvf LuaJIT-2.0..tar.gz
cd LuaJIT-2.0.
make && make install
ln -s /usr/local/lib/libluajit-5.1.so. /lib64/libluajit-5.1.so.
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0/

二、安装 GraphicsMagick

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

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

/usr/local/graphicsmagick/bin/gm version

三、安装nginx

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

./configure --prefix=/usr/local/nginx \
--dso-path=/usr/local/nginx/modules \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_concat_module \
--with-http_lua_module \
--with-pcre=/usr/local/src/pcre-8.37\
--with-zlib=/usr/local/src/zlib-1.2.\
--with-openssl=/usr/local/src/openssl-1.0.0s\
--http-proxy-temp-path=/var/tmp/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/tmp/nginx/cgi_temp \
--http-client-body-temp-path=/var/tmp/nginx/client_body_temp \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log\
--with-ld-opt="-Wl,-rpath,$LUAJIT_LIB" make && make install #启动nginx
#测试配置文件
/usr/local/nginx/sbin/nginx -t #启动
/usr/local/nginx/sbin/nginx

设置开机启动

vi /etc/rc.d/init.d/nginx 
#!/bin/bash
# Tengine Startup script# processname: nginx
# chkconfig: -
# description: nginx is a World Wide Web server. It is used to serve
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/usr/local/nginx/logs/nginx.pid
RETVAL=
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit
[ -x $nginxd ] || exit
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "tengine already running...."
exit
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
}
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;; status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit
esac
exit $RETVAL

保存退出

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

四、配置 nginx

nginx.conf

http
{
lua_package_path '/usr/local/openresty/nginx/lua/?.lua;;'; server {
listen ;
server_name img.rhythmk.org;
root /home/wwwroot/static/image; #对类似_100x100.gif/jpg/png/jpeg进行缩略图处理
location ~* _([-]+)x([-]+)\.(gif|jpg|png|jpeg)$ { #匹配文件名规则
root /home/wwwroot/static/image; #站点根目录
set $image_root /home/wwwroot/static/image; #图片目录
set $thumbnail_root /home/wwwroot/static/thumbnail; #缩略图存放目录
#如果缩略图文件存在,直接返回
set $file $thumbnail_root$uri;
if (-f $file) {
rewrite ^/(.*)$ /thumbnail/$ last;
}
#如果缩略图文件不存在,则应用缩略图模块处理
if (!-f $file) {
rewrite_by_lua_file lua/thumbnail.lua;
}
}
} #include conf/*.conf;
}

lua/thumbnail.lua

    local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)");
local originalUri = string.sub(ngx.var.uri, , index-);
local area = string.sub(ngx.var.uri, index);
index = string.find(area, "([.])");
area = string.sub(area, , index-); local image_sizes = {"80x80", "800x600", "40x40"};
function table.contains(table, element)
for _, value in pairs(table) do
if value == element then
return true
end
end
return false
end if table.contains(image_sizes, area) then
local command = "gm convert " .. ngx.var.image_root .. originalUri .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .. " " .. ngx.var.file;
os.execute(command);
ngx.req.set_uri(ngx.var.uri, true);
else
ngx.exit();
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. 关于消除if-else的简单总结

    if-else是计算机语言中基本的分支语句,虽然很简单,但可能会出现滥用的情况,如图: 这种标记判断,嵌套成这样(其实没有必要嵌套),会让别人觉得作者水平很低. 可以看出,这些if仅仅是在判断一个变量 ...

  2. mysql 5.6.17 x64 安装

    下载地址 百度网盘地址:http://pan.baidu.com/share/link?shareid=1895747668&uk=3257050114&fid=234538452 官 ...

  3. paip. dsl 编程语言优点以及 常见的dsl

    paip. dsl 编程语言优点以及  常见的dsl 作者Attilax 艾龙,  EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn. ...

  4. HTML+CSS纯干货就业前基础到精通系统学习2016/9/3

    1:HTML纯干货学习后的达到的效果 (1):会使用HTML的基本结构,创建网页 (2):会使用文本字体相关标签,实现文字修饰和布局 (3):会使用图像.超链接相关标签,实现图文并茂的页面 (4):会 ...

  5. 指定的参数错误。Vim.Host.DiskPartitionInfo.-spec VSPHERE.LOCAL\Administrator WIN-DOPGQVRRU2C

    ESXI5.5 工作需要,最近在研究虚拟化的东西. 项目做分布式开发需要很多开发服务器,公司没钱只好拿一台之前使用的Dell的服务器做虚拟机.质询了一下公司IT部门,他们使用的是vmware的一套方案 ...

  6. Java thread jargon

    In Java thread topic, the task to be executed and the thread to drive the task are two concepts shou ...

  7. SDWebImage ReadMe.md文档简单说明

    SDWebImage ReadMe.md 文档 附:SDWebImage框架github下载地址:https://github.com/rs/SDWebImage 注1:该文章简单翻译了SDWebIm ...

  8. informix 查看 当前锁表

    select username,sid,waiter,dbsname,tabname,rowidlk,keynum,type from sysmaster:syslocks l, sysmaster: ...

  9. ASP.NET Web API的安全管道

    本篇体验ASP.NET Web API的安全管道.这里的安全管道是指在请求和响应过程中所经历的各个组件或进程,比如有IIS,HttpModule,OWIN,WebAPI,等等.在这个管道中大致分两个阶 ...

  10. 使用Android Studio打Andorid apk包的流程

    启动Android studio   1.点击菜单栏Build -> Generate Signed APK...,打开如下窗口 2.这里是类似eclipse中Android的签名,假设这里没有 ...