nginx對lua指令碼的支援
阿新 • • 發佈:2020-08-02
模組語法lua指令:
set_by_lua 設定nginx變數 可以實現複雜賦值邏輯
set_by_lua_file 設定nginx變數 可以實現複雜賦值邏輯
access_by_lua 請求訪問階段處理。用於訪問控制
access_by_lua_file 請求訪問階段處理。使用者訪問控制
content_by_lua 內容處理器。 處理接受和響應輸出
content_by_lua_file 內容處理器。 處理接受和響應輸出
nginx lua api
ngx.var nginx變數
ngx.req.get_headers 獲取請求頭
ngx.req.get_uri_args 獲取url請求引數
ngx.redirect 重定向
ngx.print 輸出響應內容體
ngx.say 和 ngx.print一樣,但最後會輸出一個換行符
ngnx.header 輸出響應頭
1.直接執行個lua指令碼命令
在nginx.conf里加:
location /lua{
default_type "text/html";
content_by_lua 'ngx.say("hello world")';
}
訪問對應路徑即可在頁面輸出hello world
2.寫個lua指令碼執行
1)建立/usr/local/openresty/lua/hellolua.lua指令碼並寫ngx.say(hello world)
2)在nginx.conf里加:
location /lua{
default_type "text/html";
content_by_lua_file /usr/local/openresty/lua/hello.lua;
}