Nginx整合Lua步骤
Posted ZhiYuanYe
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nginx整合Lua步骤相关的知识,希望对你有一定的参考价值。
1、Nginx:
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
wget -c https://nginx.org/download/nginx-1.10.1.tar.gz
tar -xzf nginx-1.10.1.tar.gz
2.下载安装LuaJIT-2.0.4.tar.gz
wget -c http://luajit.org/download/LuaJIT-2.0.4.tar.gz
tar -zxf LuaJIT-2.0.4.tar.gz
cd LuaJIT-2.0.4
make install PREFIX=/usr/local/luajit
环境变量/etc/profile文件中增加环境变量,并执行source /etc/profile
export LUAJIT_LIB=/usr/local/luajit/lib
export LUAJIT_INC=/usr/local/luajit/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH
3.下载解压ngx_devel_kit
wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
tar -xzf v0.3.0.tar.gz
4.下载解压lua-nginx-module
wget https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz
tar -xzf v0.10.8.tar.gz
5、Nginx解压包下
./configure --add-module=/usr/local/ngx_devel_kit-0.3.0 --add-module=/usr/local/lua-nginx-module-0.10.8
make -j2
make install
将nginx做成命令 ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
启动:nginx 重启:nginx -s reload 关闭:nginx -s stop
错误1:
nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or
directory
解决:
环境变量/etc/profile文件中增加环境变量,并执行source /etc/profile
export LD_LIBRARY_PATH=/usr/local/luajit/lib:$LD_LIBRARY_PATH
错误2:
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid” failed (2: No such file or directory)
解决:
进入nginx安装目录下,使用nginx -c的参数指定nginx.conf文件的位置
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
测试:
#直接写nginx-lua脚本语言方式
location /hello
default_type 'text/plain';
content_by_lua 'ngx.say("hello, lua")';
#lua文件方式
#在server 中添加一个localtion
location /lua
default_type 'text/html';
content_by_lua_file conf/lua/test.lua; #nginx安装目录conf下
#test.lua中的内容
ngx.say("hello, world")
以上是关于Nginx整合Lua步骤的主要内容,如果未能解决你的问题,请参考以下文章