nginx對lua腳本的支持


nginx 對lua模塊得支持

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM