nginx配置lua模块
下面是安装nginx+lua环境时使用的相关模块及版本
yum -y install gcc gcc-c++ autoconf automake yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel useradd -s /sbin/nologin -M nginx cd /usr/local/src wget http://nginx.org/download/nginx-1.20.2.tar.gz wget http://luajit.org/download/LuaJIT-2.1.0-beta3.tar.gz wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz wget https://github.com/openresty/lua-nginx-module/archive/v0.10.14.tar.gz git clone git://github.com/yzprofile/ngx_http_dyups_module.git (可选,不用安装) tar zxf v0.3.0.tar.gz tar zxf LuaJIT-2.1.0-beta3.tar.gz tar zxf v0.10.14.tar.gz tar zxf nginx-1.20.2.tar.gz yum -y install lua-devel cd LuaJIT-2.1.0-beta3 make && make install cd .. cd nginx-1.20.2
####
下面安装会遇到坑,看最下面的报错,提前操作
#####
./configure --prefix=/usr/local/nginx --sbin-path=/usr/bin/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-pcre --with-http_stub_status_module --with-http_addition_module --with-http_gzip_static_module --with-file-aio --with-http_dav_module --add-module=../ngx_devel_kit-0.3.0 --add-module=../lua-nginx-module-0.10.14 --add-module=../ngx_http_dyups_module
#上面安装过程中报错了,所以换了下面少点的编译(手动安装编译)
./configure --prefix=/opt/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-stream --add-module=/usr/local/src/ngx_devel_kit-0.3.0 --add-module=/usr/local/src/lua-nginx-module-0.10.14 make && make install
.configure执行是成功的,但是在进行make的时候遇到报错:ngx_http_lua_common.h:20:20: error: luajit.h: No such file or directory,详细报错内容如下:
In file included from ../lua-nginx-module-0.10.15/src/ngx_http_lua_script.h:11:0,
from ../lua-nginx-module-0.10.15/src/ngx_http_lua_script.c:13:
../lua-nginx-module-0.10.14/src/ngx_http_lua_common.h:20:20: fatal error: luajit.h: No such file or directory
#include <luajit.h>
^
compilation terminated.
make[1]: *** [objs/addon/src/ngx_http_lua_script.o] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.14.2'
make: *** [build] Error 2
解决方法:把lib的路径写入/etc/profile中
vim /etc/profile export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.1 source /etc/profile
重新编译即可
启动时候报错
[root@ip sbin]# ./nginx -V
./nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
# vi /etc/ld.so.conf.d/lib.conf
/usr/local/lib
# ldconfig
[root@ip sbin]# ./nginx -V
nginx version: nginx/1.20.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-stream --add-module=/root/soft/soft/nginx/lua/ngx_devel_kit-0.3.0 --add-module=/root/soft/soft/nginx/lua/lua-nginx-module-0.10.14
测试,如果升级,需要重启nginx服务
在nginx.conf的server模块中加入如下代码
location /hello_lua { default_type 'text/plain'; content_by_lua 'ngx.say("hello, lua")'; }
<< 上一篇
下一篇 >>
网友留言(0 条)