nginx+lua_nginx+GraphicsMagick缩略图+tfs获取原图+ngx_cache_

环境介绍

root@Ubuntu-1:~# uname -a
Linux ubuntu-1.230 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
root@ubuntu-1:~# cat /etc/issue
Ubuntu 12.04.1 LTS \n \l

root@ubuntu-1:~#

PS:以下操作我只在如上系统操作,仅供参考

1.安装GraphicsMagick

GraphicsMagick 是配合im4java使用的图片处理软件,在linux/windows下均能使用。在ubuntu下安装很简单:
apt-get install graphicsmagick
 yum -y install GraphicsMagick GraphicsMagick-devel (CentOS安装方法)
然后运行 man gm,如果显示graphicsmagick的manual,则证明graphicsmagick安装成功。

2.安装lua_nginx

下载 LuaJIT-2.0.3.tar.gz  http://luajit.org/download.html

tar -zxvf LuaJIT-2.0.3.tar.gz
cd LuaJIT-2.0.3/
make && make install
所以lib和include是直接放在/usr/local/lib和usr/local/include

3.安装nginx以及需要安装模块

查看现有版本号 nginx -v

下载nginx源码,解压
wget http://www.nginx.org/download/nginx-1.7.3.tar.gz

tar -zxvf nginx-1.7.3.tar.gz

下载ngx_devel_kit HERE 解压

https://github.com/simpl/ngx_devel_kit/tags

tar -zxvf ngx_devel_kit-0.2.19.tar.gz

下载nginx_lua_module HERE 解压
https://github.com/chaoslawful/lua-nginx-module/tags

tar -zxvf lua-nginx-module-0.9.5rc2.tar.gz

下载ngx_cache_purge-1.0.tar.gz

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

tar -zxvf ngx_cache_purge-1.0.tar.gz

PS:

这里cache模块最好一起和lua进行编译安装避免后期不必要的麻烦

导入环境变量,编译
vi /etc/profile

export LUAJIT_LIB=/usr/local/lib    #这个很有可能不一样
export LUAJIT_INC=/usr/local/include/luajit-2.0  #这个很有可能不一样

是文件环境变量生效

source /etc/profile

cd nginx-1.7.3

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-rpath,$LUAJIT_LIB' --with-ipv6 --add-module=/root/ngx_devel_kit-0.2.19 --add-module=/root/lua-nginx-module-0.9.5rc2

--add-module=/path/to/ngx_devel_kit    #ngx_devel_kit 的源码路径
--add-module=/path/to/lua-nginx-module  #nginx_lua_module 的源码路径

--add-module=/path/to/ngx_cache_purge-1.0.tar.gz

 

make -j2
make install

报错:

安装nginx报错没有找到pcre包

解决办法:

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载pcre模块
编译nginx的时候添加--with-pcre=pcre源码path

****************************************************************************
这种解决pcre方法网上说,但是我按照安装出错提示,直接指定源码文件  *
安装 pcre报错                                                                                    *
checking windows.h usability... no                                                      *
checking windows.h presence... no                                                    *
checking for windows.h... no                                                              *
configure: error: You need a C++ compiler for C++ support.                  *
解决办法:                                                                                        *
apt-get install build-essential                                                              *
继续安装pcre 继续安装nginx                                                                *
--with-pcre=pcar-path                                                                        *
编译再次出错:                                                                                  *
checking for OpenSSL library ... not found                                            *
****************************************************************************

继续报错:

./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
解决办法:
apt-get install libssl-dev
apt-get install openssl
安装成功

4.测试nginx-lua模块安装是否成功

在nginx的配置文件server模块添加

location /hello {
      default_type 'text/plain';
      content_by_lua 'ngx.say("hello, lua")';
}

相关推荐