模塊語法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;
}