Nginx集成 lua-nginx-module

1.软件版本

  • 系统版本:CentOS Linux release 7.3.1611 (Core)
  • nginx版本:nginx-1.11.10
  • nginx-lua-moudle版本:lua-nginx-module 0.10.7

2.环境准备

  • 安装编译所需的依赖
yum -y install gcc gcc-c++ make libtool zlib zlib-devel openssl openssl-devel pcre pcre-devel

3.软件安装

  • 编译安装nginx
wget https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.10.7
wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
wget https://nginx.org/download/nginx-1.11.10.tar.gz
wget https://codeload.github.com/cfsego/ngx_log_if/zip/master -O ngx_log_if-master.zip

groupadd nginx
useradd -g nginx -s /sbin/nologin nginx

mkdir -p /var/tmp/nginx/client/
mv v0.10.7 lua-nginx-module-0.10.7.tar.gz
tar -zxvf ./nginx-1.11.10.tar.gz

tar -zxvf ./lua-nginx-module-0.10.7.tar.gz

tar -zxvf ./LuaJIT-2.0.4.tar.gz

unzip ngx_log_if-master.zip -d /usr/local/nginx/

cd LuaJIT-2.0.4/

make && make install

cat >> /etc/profile <<EOF export LUAJIT_LIB=/usr/local/lib export LUAJIT_INC=/usr/local/include/luajit-2.0 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH EOF

source /etc/profile

cd ../nginx-1.11.10/

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --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/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre --add-module=../lua-nginx-module-0.10.7 --add-module=../ngx_log_if-master

make -j2

make install
  • 测试nginx配置是否成功
cd ../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

  • 安装dkjson.lua插件

cd /usr/local/share/lua/5.1

wget http://dkolf.de/src/dkjson-lua.fsl/raw/dkjson.lua?name=16cbc26080996d9da827df42cb0844a25518eeb3 -O dkjson.lua

cd /usr/local/nginx

touch dkjson.lua
vim dkjson.lua
  • dkjson.lua 文件内容如下
local s = ngx.var.request_body

local dkjson = require("dkjson")

local obj = { code = 0, message = "ok" }

local str = dkjson.encode(obj, {indent = true})

ngx.say(str)
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值