暂做笔记,带后续验证通过后,再补充 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.1.tar.gz #进入解压目录
make linux && make install

wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar zxvf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make && make install

ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
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.21.tar.gz
cd GraphicsMagick-1.3.21
./configure  --prefix=/usr/local/graphicsmagickmake && 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.8\--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: - 85 15
# 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=0
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 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "tengine already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && 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 1
esac
exit $RETVAL

保存退出

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

四、配置 nginx

nginx.conf

http{lua_package_path '/usr/local/openresty/nginx/lua/?.lua;;';server {listen       80;server_name  img.rhythmk.org;root  /home/wwwroot/static/image;#对类似_100x100.gif/jpg/png/jpeg进行缩略图处理location ~* _([0-9]+)x([0-9]+)\.(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/$1 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, 0, index-2);  local area = string.sub(ngx.var.uri, index);  index = string.find(area, "([.])");  area = string.sub(area, 0, index-1);  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(404);  end;  

nginx+lua_nginx+GraphicsMagick生成实时缩略图相关推荐

  1. nginx+lua+GraphicsMagick生成实时缩略图-CentOS7

    背景说明 大多数的系统都会涉及缩略图的处理,比如新闻系统和电商系统,特别是电商系统,每个商品大图都会对应一系列尺寸的缩略图用于不同业务场景的使用.部分系统也会生成不同尺寸的缩略图以供PC.手机端.ip ...

  2. ftp+nginx+lua_Nginx+GraphicsMagick来实现目录浏览、实时缩略图

    一.FTP服务器安装配置 1.rpm -ivh vsftpd-2.2.2-11.el6_4.1.i686.rpm 2.service vsftpd start 3.chkconfig vsftpd o ...

  3. 2018-CropNet实时缩略图论文笔记

    2018-CropNet : Real-Time Thumbnailing 摘要 1 简介 裁剪步骤和缩放步骤的引入 缩略图生成与目标检测的异同 CropNet的提出 数据集的选取以及实验结果 2 相 ...

  4. Nginx代理浏览器可实时查看程序日志

    我们经常需要在页面上实时查看nginx的日志输出,并且能在页面上显示,那么如何通过Nginx实现浏览器可实时查看访问日志呢? 一.首先查看nginx版本,我使用的是1.20.1的版本,安装目录在/ap ...

  5. [C#]解决生成的缩略图模糊的问题

    一.问题场景 针对一张正方形图片生成 48px × 48px 的缩略图并保存为图片文件,但发现生成的缩略图很模糊. 生成的模糊的缩略图如下: 原始图片(300px × 300px, png格式): 代 ...

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

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

  7. php生成网页缩略图接口,php生成网站缩略图

    我要明确的回答使用php生成网站缩略图是不可能完成的任务. 那为什么我标题还要用"php生成网站缩略图",那是因为我们可以用php作为接口,通过页面传入参数来调用后台生成网页的缩略 ...

  8. c#.net 生成清晰缩略图的解决方案

    Bitmap类的GetThumbnailImage方法可以从指定的图像文件中生成缩略图,但是这种方式生成的缩略图清晰度不稳定,有时生成的缩略图的质量很差--模糊不清! 为什么会这样?为什么生成的图片是 ...

  9. 【下载源码】在线生成网页缩略图.超越Snap.com:WebSnap Beta 1.1 发布。感谢博客园的“萧寒”重写的底层。开源。

    [下载源码]在线生成网页缩略图.超越Snap.com:WebSnap Beta 1.1 发布.感谢博客园的"萧寒"重写的底层.开源. DEMO网址:http://www.365rs ...

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

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

最新文章

  1. bootstrap行内编辑后提交多条数据到ssm
  2. CAD2011软件安装资料及教程
  3. windows系统命令行下常用命令收集
  4. mysql自增主键到头了怎么办_自增主键用完了怎么办
  5. scrapy框架_入门Scrapy框架看这一篇文章就够了
  6. 数据结构与算法--3.字符串的旋转
  7. Linux CentOS7/RHEL7关闭ctrl+alt+delete功能键
  8. 我的第一个C++程序——方块游戏 v1.0
  9. 【恋上数据结构】图代码实现、BFS、DFS、拓扑排序
  10. HDU 2639 Bone Collector II (dp)
  11. Enterprise Library 4.1 Security Block 快速使用图文笔记
  12. linux 开机自动运行命令_Linux内核分析-启动顺序、运行级别及开机启动(七)
  13. Oracle数据库 入门教程
  14. java商城系统设计-----积分商城系统
  15. 前端PDF文件转图片方法
  16. Eclipse没有Dynamic Web Project选项解决
  17. Linux环境下安装tomcat并配置开机自启
  18. linux命令scp和sftp
  19. HRBUST 1849 商品中心
  20. linux下c/c++读取txt文件,多行文件,且每行都用逗号隔开

热门文章

  1. 安卓命令和linux命令行,scrcpy:用电脑显示和控制Android设备的命令行工具
  2. 【学习Spring框架】依赖注入和控制反转异同?
  3. C语言实现24点小游戏,C语言解24点游戏程序
  4. php while次数,PHP While 循环
  5. sql create 在关键字 view 附近有语法错误_MySQL中,21个写SQL的好习惯,值得培养
  6. linux整盘远程备份,linux实现自动远程备份(scp+ssh)
  7. Netty学习(三)高性能之ByteBuf源码解析(篇幅较长)
  8. 二十一、 Memento 备忘录(行为型模式)
  9. Codeforces 145E Lucky Queries 线段树
  10. API Monitor简介(API监控工具)