nginx 增加lua 扩展(还是直接用openresty吧)
1、加扩展
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#lua wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz tar -zxvf LuaJIT-2.0.5.tar.gz cd LuaJIT-2.0.5 make && make install PREFIX=/usr/local/LuaJIT cat >> /etc/profile < EOF export LUAJIT_LIB=/usr/local/LuaJIT/lib export LUAJIT_INC=/usr/local/LuaJIT/include/luajit-2.0 source /etc/profile EOF lua -v #扩展 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.9rc7.tar.gz # 解压 tar -zxf v0.3.0.tar.gz tar -zxf v0.10.9rc7.tar.gz ./configure --prefix=/opt/nginx --pid-path=/opt/nginx/nginx.pid --user=www --group=www --with-poll_module --with-threads --with-file-aio --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --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_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_geoip_module=dynamic --with-stream_ssl_preread_module --with-google_perftools_module --with-compat --with-pcre --with-debug --add-module=/opt/soft/lua-nginx-module-0.10.9rc7 --add-module=/opt/soft/ngx_devel_kit-0.3.0 echo "/usr/local/LuaJIT/lib" >> /etc/ld.so.conf ldconfig
2、修改配置
#new set $resp_header ""; header_filter_by_lua ' local h = ngx.resp.get_headers() for k, v in pairs(h) do ngx.var.resp_header=ngx.var.resp_header..k..": "..v end '; set $response_body ""; body_filter_by_lua ' local response_body = string.sub(ngx.arg[1],1,1000) ngx.ctx.buffered = (ngx.ctx.buffered or "") .. response_body if ngx.arg[2] then ngx.var.response_body = ngx.ctx.buffered end ';