日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx lua以html显示,nginx 支持lua及lua脚本格式化日志

發(fā)布時(shí)間:2023/12/4 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx lua以html显示,nginx 支持lua及lua脚本格式化日志 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.安裝LuaJIT-2.0.4

鏈接:

http://luajit.org/download.html

tar?-xf?LuaJIT-2.0.4.tar.gz

cd?LuaJIT-2.0.4

make?PREFIX=/usr/local/luajit

make?install?PREFIX=/usr/local/luajit

2.修改環(huán)境變量

vim?/etc/profile

export?LUAJIT_LIB=/usr/local/luajit/lib

export?LUAJIT_INC=/usr/local/luajit/include/luajit-2.0

source?/etc/profile

3.下載nginx lua模塊

ngx_devel_kit 鏈接:https://github.com/simpl/ngx_devel_kit/tags

lua-nginx-module 鏈接:https://github.com/openresty/lua-nginx-module/tags

4.編譯nginx 增加支持模塊

cd?/tmp/soft/

tar?-xf?ngx_devel_kit-0.3.0.tar.gz

tar?-xf?lua-nginx-module-0.10.5.tar.gz

4.1.編譯nginx

tar?-xf?nginx-1.9.14.tar.gz

cd?nginx-1.9.14

./configure?\

--prefix=/app/local/nginx?\

--pid-path=/app/local/nginx?\

--user=nginx?\

--group=nginx?\

--with-threads?\

--with-file-aio?\

--with-http_ssl_module?\

--with-http_v2_module?\

--with-http_addition_module?\

--with-http_sub_module?\

--with-http_dav_module?\

--with-http_flv_module?\

--with-http_mp4_module?\

--with-http_perl_module?\

--with-mail?\

--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-zlib=/tmp/soft/zlib-1.2.8?\

--with-stream?\

--with-stream_ssl_module?\

--with-pcre=/tmp/soft/pcre-8.37?\

--with-openssl=/tmp/soft/openssl-1.0.2?\

--with-libatomic?\

--add-module=/tmp/soft/ngx_log_if-master?\

--add-module=/tmp/soft/ngx_devel_kit-0.3.0?\

--add-module=/tmp/soft/lua-nginx-module-0.10.5

make

5.備份原有的程序及增加鏈接

mv?/app/local/nginx/sbin/nginx?/app/local/nginx/sbin/nginx.0729

cp?./objs/nginx?/app/local/nginx/sbin/

ln?-s?/usr/local/lib/libpcre.so.1?/lib64/libpcre.so.1

ln?-s?/usr/local/luajit/lib/libluajit-5.1.so.2?/lib64/libluajit-5.1.so.2

6.查看模塊

#?/app/local/nginx/sbin/nginx?-V

nginx?version:?nginx/1.9.14

built?by?gcc?4.4.7?20120313?(Red?Hat?4.4.7-17)?(GCC)

built?with?OpenSSL?1.0.2?22?Jan?2015

TLS?SNI?support?enabled

configure?arguments:?--prefix=/app/local/nginx?--pid-path=/app/local/nginx?--user=nginx?--group=nginx?--with-threads?--with-file-aio?--with-http_ssl_module?--with-http_v2_module?--with-http_addition_module?--with-http_sub_module?--with-http_dav_module?--with-http_flv_module?--with-http_mp4_module?--with-http_perl_module?--with-mail?--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-zlib=/tmp/soft/zlib-1.2.8?--with-stream?--with-stream_ssl_module?--with-pcre=/tmp/soft/pcre-8.37?--with-openssl=/tmp/soft/openssl-1.0.2?--with-libatomic?--add-module=/tmp/soft/ngx_log_if-master?--add-module=/tmp/soft/ngx_devel_kit-0.3.0?--add-module=/tmp/soft/lua-nginx-module-0.10.5

7.nginx 修改為json格式

修改很簡單,如下:

log_format?ng_json?'{'

'"http_cdn_src_ip":"$http_cdn_src_ip",'

'"time_local":?"$time_local",'

'"request":"$request",'

'"status":"$status",'

'"body_bytes_sent":"$body_bytes_sent",'

'"request_body":"$request_body",'

'"content_length":"$content_length",'

'"http_referer":"$http_referer",'

'"http_user_agent":"$http_user_agent",'

'"http_x_forwarded_for":"$http_x_forwarded_for",'

'"remote_addr":"$remote_addr",'

'"upstream_response_time":"$upstream_response_time",'

'"request_time":"$request_time",'

'"http_x_trace_code":"$http_x_trace_code"}

}';

查看生成的json:

{

"http_cdn_src_ip":?"-",

"time_local":?"29/Jul/2016:03:01:02?+0800",

"request":?"GET?/q.gif?platform=pc&category=player&action=bufferEmpty&t=1469732461170&loc=/star/3459038?HTTP/1.1",

"status":?"200",

"body_bytes_sent":?"43",

"request_body":?"-",

"content_length":?"-",

"http_referer":?"http://www.ckl.com/ckl/3459038",

"http_user_agent":?"Mozilla/5.0?(Windows?NT?6.1;?WOW64)?AppleWebKit/537.36?(KHTML,?like?Gecko)?Chrome/38.0.2125.122?BIDUBrowser/7.5?Safari/537.36",

"http_x_forwarded_for":?"-",

"remote_addr":?"117.174.247.112",

"upstream_response_time":?"-",

"request_time":?"0.000",

"http_x_trace_code":?"-"

}

發(fā)現(xiàn),request 字段依然不是json格式,如何修改,nginx測試無法實(shí)現(xiàn)(自己無法實(shí)現(xiàn))所以修改了,增加lua腳本,不通過nginx記錄日志

而是直接使用lua來記錄,lua腳本如下:

#cd?/app/local/nginx/lua/

#vim?parse.lua

local?args?=?{}

args?=?ngx.req.get_uri_args()

local?v_prev?=?""

local?sp?=?"\""

for?key,val?in?pairs(args)?do

if?key?==?nil?or?val?==?nil?then

else

v_prev?=?v_prev?..?sp?..??key?..?sp?..?":"?..?sp?..?val?..?sp?..?","

end

end

function?isnil(value)

if?value?==?nil?then

value?=?"-"

end

return?value

end

local?logContent?=?""

if?v_prev?~=?nil?then

local?http_cdn_src_ip?=?isnil(ngx.var.http_cdn_src_ip)

local?time_local?=?isnil(ngx.var.time_local)

local?status?=?isnil(ngx.var.status)

local?body_bytes_sent?=?isnil(ngx.var.body_bytes_sent)

local?request_body?=?isnil(ngx.var.request_body)

local?content_length?=?isnil(ngx.var.content_length)

local?http_referer?=?isnil(ngx.var.http_referer)

local?http_user_agent?=?isnil(ngx.var.http_user_agent)

local?http_x_forwarded_for?=?isnil(ngx.var.http_x_forwarded_for)

local?remote_addr?=?isnil(ngx.var.remote_addr)

local?upstream_response_time?=?isnil(ngx.var.upstream_response_time)

local?request_time?=?isnil(ngx.var.request_time)

local?http_x_trace_code?=?isnil(ngx.var.http_x_trace_code)

logContent?=?"{\"http_cdn_src_ip\":"?..?sp?..?http_cdn_src_ip?..?sp?..?",\"time_local\":"?..?sp?..?time_local?..?sp??..?",\"request\":"?..??"{"?..?string.sub(v_prev,1,#v_prev-1)?..??"}"?..?",\"status\":"?..?sp?..?status?..?sp?..?",\"body_bytes_sent\":"?..?sp?..?body_bytes_sent?..?sp?..?",\"request_body\":"?..?sp?..?request_body?..?sp?..?",\"content_length\":"?..?sp?..?content_length?..?sp?..?",\"http_referer\":"?..?sp?..?http_referer?..?sp?..?",\"http_user_agent\":"?..?sp?..?http_user_agent?..?sp?..?",\"http_x_forwarded_for\":"?..?sp?..?http_x_forwarded_for?..?sp?..?",\"remote_addr\":"?..?sp?..?remote_addr?..?sp?..?",\"upstream_response_time\":"?..?sp?..?upstream_response_time?..?sp?..?",\"request_time\":"?..?sp?..?request_time?..?sp?..?",\"http_x_trace_code\":"?..?sp?..?http_x_trace_code?..?sp?..?"}"

local?file?=?io.open("/app/data/log/nginx/ckl_access.log","a")

local?hc?=?"\n"

file:write(logContent)

file:write(hc)

file:close()

end

ngx.status?=?200

ngx.exit(0)

修改nginx配置:

增加如下:

location?~?/ckl.gif?{

set?$logContent?"";

default_type?text/plain;

content_by_lua_file?"/app/local/nginx/lua/parse.lua";

}

重啟nginx 生效,這個(gè)必須重啟

/etc/init.d/nginx?restart

查看新的json

{

"http_cdn_src_ip":?"-",

"time_local":?"01/Aug/2016:02:01:02?+0800",

"request":?{

"t":?"1469988090580",

"category":?"player",

"action":?"bufferEmpty",

"platform":?"pc",

"loc":?"/v/2955653"

},

"status":?"000",

"body_bytes_sent":?"0",

"request_body":?"-",

"content_length":?"-",

"http_referer":?"http://www.ckl.com/v/2955653",

"http_user_agent":?"Mozilla/5.0?(Windows?NT?6.1;?WOW64)?AppleWebKit/537.36?(KHTML,?like?Gecko)?Chrome/45.0.2454.101?Safari/537.36",

"http_x_forwarded_for":?"-",

"remote_addr":?"221.226.105.101",

"upstream_response_time":?"-",

"request_time":?"0.000",

"http_x_trace_code":?"-"

}

總結(jié)

以上是生活随笔為你收集整理的nginx lua以html显示,nginx 支持lua及lua脚本格式化日志的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 97国产精品视频人人做人人爱 | 蜜桃臀av在线 | 麻豆精品视频免费观看 | 精品国产免费无码久久久 | 深夜小视频在线观看 | 日本免费视频 | 亚洲国产精品成人综合色在线婷婷 | 欧美在线免费观看 | 伊人一区| 人禽高h交| 嫩草影院久久 | 国产靠逼视频 | 俄罗斯色片 | 香蕉av网站 | 日韩精品乱码久久久久久 | 国产精品日韩电影 | 欧美视频www | 久久中文字幕高清 | 人妻少妇精品久久 | 97国产精品 | xxx一区| 亚洲另类色综合网站 | 性欧美视频在线观看 | 美女视频黄频视频大全 | 国产午夜网站 | 91久操| 综合久久综合久久 | 日韩在线天堂 | 国产偷自拍视频 | 性欧美ⅴideo另类hd | 蜜臀久久久久久999 大陆熟妇丰满多毛xxxⅹ | 亚洲av无码成人精品国产 | 国产精品播放 | 久久成人资源 | 午夜激情av| 一级片一区| 99国产精品一区二区 | 久久久情 | 九九热免费在线视频 | 人成免费在线视频 | 久久国产精品无码一区二区 | 国产农村妇女毛片精品久久 | 亚洲熟女少妇一区 | 熟女熟妇伦久久影院毛片一区二区 | 日韩美女免费视频 | 国模av在线 | 国产传媒在线 | 精品视频一区二区在线观看 | 射久久 | 一区二区三区av夏目彩春 | 顶级嫩模啪啪呻吟不断好爽 | 国外成人性视频免费 | 国产精品无码成人片 | 萌白酱一区二区 | 欧美在线影院 | 长篇高h乱肉辣文 | 欧美日韩精品一区 | 天天操天天拍 | 91沈先生在线 | 日韩图色| 欧美一级欧美三级 | 亚洲一区免费电影 | 欧洲日韩一区二区三区 | 97超碰免费观看 | 夜夜欢天天干 | 久久久精品电影 | 日韩av综合| 最新av中文字幕 | 亚洲一区二区在线视频 | 嫩草懂你 | 青青操网站 | 亚洲黄色网页 | 国产男男gay网站 | 女优中文字幕 | 日韩av高清在线观看 | 久久久国产成人一区二区三区 | 成人在线不卡视频 | 亚洲a免费| 亚洲影视网| 中文字幕在线观看一区二区三区 | 丁香激情六月 | 亚洲欧美日韩在线看 | 青青草青娱乐 | 毛片视频在线免费观看 | 秋葵视频污 | 国产调教 | 精品国产一区二区三区性色 | 久久免费看视频 | 夜夜草网 | 狠狠一区二区 | 99精品久久久久久中文字幕 | 欧美日韩影院 | 国产精品亚洲色图 | 国内爆初菊对白视频 | 99国产精品99久久久久久 | 欧美精品在线免费观看 | 亚洲天堂男 | 亚洲精品乱码久久久久久麻豆不卡 | 欧美日韩另类在线 |