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 on

4、配置

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

vim /etc/vsftpd/vsftpd.conf

12 anonymous_enable=NO 禁止匿名訪問
...
121 chroot_local_user=yes
禁錮登錄目錄
122 local_root=/usr/local/nginx/html/test 改登錄目錄爲/usr/local/nginx/html/test
123 userlist_deny=NO 白名單生效

124 max_clients=20 最大併發客戶端
125 max_per_ip=2 每ip最大併發
126 local_max_rate=100000 限制下載速度
5、白名單配置

tail -1 /etc/vsftpd/user_list

test

6、添加FTP用戶、用戶組及相關權限

# groupadd test

添加test用戶組,用來承載我們的FTP授權用戶。
# useradd -g test -M -d /usr/local/nginx/html/test -s /sbin/nologin test

使用-g參數將它歸集到test用戶組下,-M參數不設置它的主目錄(沒有-M參數/home裏會有個test文件夾,這個文件夾沒多少實際用處,所以不用設置),-d參數設定它的初始登入目錄爲/usr/local/nginx/html/test,-s參數設定它不需要登陸系統/sbin/nologin。

7、修改FTP用戶密碼及目錄權限

passwd test

chown –R /usr/local/nginx/html/test

8、重啓

service vsftpd restart

9、訪問測試

   ftp://test:[email protected]

二、Nginx+lua_Nginx+GraphicsMagick來實現實時縮略圖

安裝libpng

   wget http://www.imagemagick.org/download/delegates/libpng-1.6.2.tar.gz

tar xf libpng-1.6.21.tar.gz -C /usr/local/

./configure

make && make install

ln -s /usr/local/libpng-1.6.21/.libs/libpng16.so.16 /lib64/libpng16.so.16

安裝jpeg-9a

    wget http://www.imagemagick.org/download/delegates/jpegsrc.v9a.tar.gz

tar xf jpegsrc.v9a.tar.gz -C /usr/local/

./configure

make && make install

ln -s /usr/local/jpeg-9a/.libs/libjpeg.so.9 /lib64/libjpeg.so.9

1、安裝GraphicsMagick

spacer.gif

wget http://sourceforge.net/projects/graphicsmagick/files/graphicsmagick/1.3.20/GraphicsMagick-1.3.20.tar.gz/download

tar -zxvf  GraphicsMagick-1.3.20.tar.gz

 

cd GraphicsMagick-1.3.20

 

./configure --prefix=/usr/local/GraphicsMagick

make && make install

spacer.gif

2、下載luajit

spacer.gif

a.下載

 

  wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz

 

b.解壓

 

tar -zxvf LuaJIT-2.0.4.tar.gz

 

c.進入解壓目錄

 

cd LuaJIT-2.0.4

 

d.安裝

 

make

 

make install

 

e.建立軟連接

 

ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

f.測試 luajit

 

退出編輯 :Ctrl + D 保存退出

 

安裝 lua

1.首先確認是否安裝 readline

 rpm -qa|grep -i readline

 

yum安裝readline

 

 yum -y install readline-devel ncurses-devel

 

2.安裝lua

 

2.1 lua安裝

 

a.下載lua

 

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

 

b.解壓lua-5.3.1.tar.gz

 

tar zxvf lua-5.3.1.tar.gz

 

c.進入解壓目錄

cd lua-5.3.1

 

d.安裝

 

make linux && makeinstall

 

 

make linux

 

make install

 

e。測試

 

lua命令:

 

在編輯模式中輸入:

 

print('Hi,this is  my first lua program!')

 

回車

 

問題:error while loading shared libraries: xxx.so.0:cannot open shared object file: No such file or directory

 

出現這類錯誤表示,系統不知道xxx.so放在哪個目錄下,這時候就要在/etc/ld.so.conf中加入xxx.so所在的目錄。

 

一般而言,有很多的so會存放在/usr/local/lib這個目錄底下,去這個目錄底下找,果然發現自己所需要的.so文件。

 

所以,在/etc/ld.so.conf中加入/usr/local/lib這一行,保存之後,再運行:/sbin/ldconfig –v更新一下配置即可。

 

 

 

 

cd /usr/src

 

spacer.gif

3、下載  ngx_devel_kit 模塊

wget https://github.com/simpl/ngx_devel_kit/archive/master.zip

unzip master.zip

4、下載 lua-nginx-module 模塊

https://github.com/openresty/lua-nginx-module/archive/master.zip

unzip master.zip


5
、下載echo

 https://github.com/agentzh/echo-nginx-module/zipball/master

unzip echo-nginx-module.zip 

6、下載cache

spacer.gif

wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz

tar -zxvf ngx_cache_purge-2.1.tar.gz

 

cd ngx_cache_purge-2.1

 

...

 

spacer.gif

7、下載nginx

wget http://nginx.org/download/nginx-1.7.5.tar.gz

...


8
、設置環境變量

spacer.gif

export LUAJIT_LIB=/usr/local/lj2/lib

 

export LUAJIT_INC=/usr/local/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;

 

PATH=$GM_HOME/bin:$PATH;

 

export PATH

 

export GM_HOME

 

source /etc/profile

spacer.gif

 

9、nginx 編譯安裝


./configure --prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/usr/local/src/ngx_devel_kit-master --with-ld-opt=-Wl,-rpath,/usr/local/lib --add-module=/usr/local/src/ngx_cache_purge-2.3 --with-http_perl_module --add-module=/usr/local/src/echo-nginx-module --add-module=/usr/local/src/lua-nginx-module-master --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx/nginx.pid --user=nginx --group=nginx --with-http_ssl_module  --with-http_flv_module --with-http_gzip_static_module --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fcgi --with-http_stub_status_module

make && make install

注意:安裝的時候出錯找不到perl。

 

yum -y install perl-devel perl-ExtUtils-Embed

 

 

 

10、nginx配置

11、虛擬目錄vhost

spacer.gif

server {

        listen 80;

        server_name image.host.com;

        root /usr/local/nginx/html/test;

        index index.html index.htm index.php;

 

        location /lua1 {

 

            default_type 'text/plain';

            content_by_lua 'ngx.say("hello, lua")';

        }

 

         location  /image {

 

            set $image_root /usr/local/nginx/html/test;

 

            set $file "$image_root$uri";

 

            if (!-f $file) {

                        rewrite_by_lua '                                local index = string.find(ngx.var.uri, "([0-9]+)x([0-9]+)");

                                if (index == nil) then

                                   ngx.exit(404);end;

                                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 = {"160x160","400x300"};

                                local image_big = {"80x60^", "120x90^", "160x120^"};

                                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_big, area) then

                        local command = "/usr/local/GraphicsMagick/bin/gm convert " .. ngx.var.image_root ..  originalUri  .. " -thumbnail " .. area .. " -background gray -gravity center -extent " .. area .. " " .. ngx.var.image_root .. ngx.var.uri

                        os.execute(command);

                else

                        if table.contains(image_sizes, area) then

                        local command = "/usr/local/GraphicsMagick/bin/gm convert " .. ngx.var.image_root ..  originalUri  .. " -thumbnail "  .. area .. " " .. ngx.var.image_root .. ngx.var.uri;

                        os.execute(command);

                        else

                        ngx.exit(404);

                        end;

                end;

                ';          }

          # alias /usr/local/nginx/html/test/image;

 

          expires 7d;

    }

}

spacer.gif

12、賦予權限

chmod o+w /usr/local/nginx/html/test/image

13、訪問

原地址:http://image.host.com/image/2.jpg

縮略圖地址:http://image.host.com/image/2.jpg.400x300.jpg

14、參考文檔

http://www.cnblogs.com/kezf/p/lua_nginx.html

 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章