您的位置:首页 > 运维架构 > Nginx

Lua-nginx-module的安装

2017-04-16 16:26 597 查看
Lua-nginx-module的安装

该模块的安装可以直接安装集成包OpenResty,也可以一个一个模块的逐步安装,下面就这两个方法进行介绍:

不管是单模块安装还是直接安装集成包

Zlib,Pcre都得安装

安装pcre

root@iZm5e5rrsi4gkk:/tmp# wget https://ftp.pcre.org/pub/pcre/pcre-8.36.zip
cd pcre-8.36

root@iZm5e5rrsi4gkk:/tmp# ./configure && make && make install

安装zlib

root@iZm5e5rrsi4gkk:/tmp#wget  https://sourceforge.net/projects/libpng/files/zlib/1.2.11/zlib-1.2.11.tar.gz

cd zlib-1.2.11

root@iZm5e5rrsi4gkk:/tmp# ./configure && make && make install

如果没有lua

执行命令 apt-get install lua5.1 

一,单模块安装

下载ngx_devel_kit

root@iZm5e5rrsi4gkk:/tmp# wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.zip
unzip 解压

下载 lua-nginx-module

root@iZm5e5rrsi4gkk:/tmp# wget https://github.com/openresty/lua-nginx-module/archive/v0.10.7.zip
unzip 解压

将ngx_devel_kit和lua_nginx_module用到opt目录

root@iZm5e5rrsi4gkk:/opt# mv /tmp/ngx_devel_kit-0.3.0/ /opt/

root@iZm5e5rrsi4gkk:/opt# dir

ngx_devel_kit-0.3.0

root@iZm5e5rrsi4gkk:/opt# mv /tmp/lua-nginx-module-0.10.7/ /opt/

root@iZm5e5rrsi4gkk:/opt# dir

lua-nginx-module-0.10.7  ngx_devel_kit-0.3.0

root@iZm5e5rrsi4gkk:/opt# 

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# export LUAJIT_LIB=/usr/local/lib/

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3#export LUAJIT_INC=/usr/local/include/luajit-2.0/

安装nginx   

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# ./configure    --add-module=/opt/ngx_devel_kit-0.3.0 --add-module=/opt/lua-nginx-module-0.10.7

再make && make install

启动nginx  /user/local/nginx/sbin/nginx

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# /usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# 

报错

解决方法如下:

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# echo "/usr/local/lib/" > /etc/ld.so.conf.d//usr_local_lib.conf

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# ldconfig

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# /usr/local/nginx/sbin/nginx -t

nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

root@iZm5e5rrsi4gkk:/tmp/nginx-1.10.3# 

成功

二,OpenResty安装

安装openssl

wget https://www.openssl.org/source/openssl-1.0.2k.tar.gz
tar -zxvf openssl-1.0.2k.tar.gz

[root@iZm5eaxgp4 tmp]# cd openssl-1.0.2k

[root@iZm5eaxg openssl-1.0.2k]# ./config && make && make install

安装openresty

wget https://openresty.org/download/openresty-1.11.2.1.tar.gz
tar -zxvf openresty-1.11.2.1.tar.gz

[root@localhost openresty-1.11.2.1]#./configure --with-luajit --with-openssl=../openssl-1.0.2j --with-pcre=../pcre-8.36 -j4 && make && make install

启动Nginx即可

在nginx.conf 写上实例

用 content_by_lua 编写lua语句

server {

listen 8080;

location /{

default_type text/html;

content_by_lua 'ngx.say("<p>Hello,World! JasonLi. ")';

}

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息