一、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
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
2、下载luajit
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
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
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
...
7、下载nginx
wget http://nginx.org/download/nginx-1.7.5.tar.gz
...
8、设置环境变量
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
9、nginx 编译安装
--prefix=/usr/local/nginx --with-http_stub_status_module --add-module=/usr/src/simpl-ngx_devel_kit --with-ld-opt=-Wl,-rpath,/usr/local/lj2/lib --add-module=/usr/src/ngx_cache_purge-2.1 --with-http_perl_module --add-module=/usr/local/src/lua-nginx-module --add-module=/usr/local/src/echo-nginx-module-master
如果编译有错,请把pcre扩展附加上
./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
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;
}
}
12、赋予权限
chmod o+w /usr/local/nginx/html/test/image
13、访问
原地址:http://image.rose.com/image/2.jpg
缩略图地址:http://image.rose.com/image/2.jpg.400x300.jpg