CentOS install Nginx+lua_nginx+graphicsmagick generate real time thumbnails

Source: Internet
Author: User
Tags echo command lua zip

Download:
Software download address:
http://soft.ileiming.com/gm.tar.gz
Installation

/table>
  code is as follows copy code

TAR-ZXVF gm.tar.gz
TAR-ZXVF graphicsmagick-1.3.12.tar.gz
CD GraphicsMagick-1.3.12
./configure–prefix=/usr/local/ GM
make && make install

TAR-ZXVF luajit-2.0.0-beta10.tar.gz
CDs luajit-2.0.0-beta10
Make & & make install prefix=/usr/local/lj2
LN-SF Luajit-2.0.0-beta10/usr/local/lj2/bin/luajit

Unzip Simpl-ngx_devel_kit-v0.2.19-0-g8dd0df5.zip

tar-zxvf  chaoslawful-lua-nginx-module-v0.9.2-61-ge4e085f.tar.gz

Unzip Agentzh-echo-nginx-module-v0.49-1-g84feae9.zip

TAR-ZXVF ngx_cache_purge-1.6.tar.gz

Setting environment variables

The code is as follows Copy Code
Export Luajit_lib=/usr/local/lj2/lib
Export luajit_inc=/usr/local/lj2/include/luajit-2.0
Export ld_library_path=/usr/local/lib/: $LD _library_path
Export Pkg_config_path=/usr/local/lib/pkgconfig: $PKG _config_path
gm_home=/usr/local/graphicsmagick-1.3.16;
Path= $GM _home/bin: $PATH;
Export PATH
Export Gm_home

Make environment variable effective: source/etc/profile

The code is as follows Copy Code
TAR-ZXVF nginx-1.2.1.tar.gz
CD nginx-1.2.1
./configure–prefix=/usr/local/nginx5–user=www–group=www–with-http_stub_status_module–add-module=/root/gm/ simpl-ngx_devel_kit-8dd0df5–with-ld-opt=-wl,-rpath,/usr/local/lj2/lib–add-module=/root/gm/ngx_cache_purge-1.6– with-http_perl_module–add-module=/root/gm/chaoslawful-lua-nginx-module-e4e085f–add-module=/root/gm/ Agentzh-echo-nginx-module-84feae9–with-pcre

If the error is correct, it is most likely that Lua and Lua-devel are not installed
Direct Yum installation can:

The code is as follows Copy Code
# Yum Install Lua Lua-devel

##########################################

Nginx configuration file

The code is as follows Copy Code

server {
Listen 80;
server_name 192.168.1.199;
Root/usr/local/nginx5/html/test;
Index index.html index.htm index.php;

location/image/{
Set $image _root/usr/local/nginx5/html/test;
Set $file $image _root$uri;
Set $forward _url "";

if (!-e $file) {
Rewrite_by_lua '
Local Originaluri = nil;
Local area = nil;
Local index = String.find (Ngx.var.uri, "([0-9]+) x ([0-9]+)");
Local Ouindex = nil;
Local fileextname = nil;
Local filesuffix = nil;
If index ~= nil then
Originaluri = string.sub (Ngx.var.uri, 0, index-2);
Ouindex = String.find (Originaluri, "([.])");
Fileextname = String.sub (originaluri,ouindex+1);
Filesuffix = String.sub (originaluri,0,ouindex-1);
Area = String.sub (Ngx.var.uri, index);
index = string.find (area, "([.])");
If index ~= nil then
Area = string.sub (area, 0, index-1);
End
End
If Originaluri ~= Nil Then
Local command = "/usr/local/gm/bin/gm convert". Ngx.var.image_root.. Originaluri.. "-thumbnail". Area.. "-background gray-gravity center-extent". Area.. " ".. Ngx.var.image_root.. Originaluri ... " _" .. Area.. ".".. Fileextname;
Os.execute ("Echo command" ... command ...) >>/usr/local/nginx5/html/123.txt ");

                                 os.execute (command);
                                 Ngx.var.forward_url = Filesuffix ... " _thumb. " Fileextname;

Else
Ngx.var.forward_url = Ngx.var.uri;
End
';

}

}

}

The above configuration is simply to generate a thumbnail configuration, through the Nginx to control LUA can also achieve only a fixed size of the picture or, can also call a folder of pictures generated into the B folder and other very useful features

Access with Yun_qi_img/1.jpg_200x200.jpg

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.