Lua:Nginx Lua環境配置,第一個Nginx Lua代碼


一、編譯安裝LuaJIT

        Lua:編譯安裝LuaJIT,第一個Lua程序

                http://blog.csdn.net/guowenyan001/article/details/48250427

二、下載NDK與Lua_module

2.1 下載NDK,解壓縮

        wget -c https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz

        tar zxvf v0.2.18

2.2 下載Lua_module,解壓縮

        wget -c https://github.com/chaoslawful/lua-nginx-module/archive/v0.8.6.tar.gz

        tar zxvf v0.8.6

三、編譯安裝Nginx

        Nginx編譯:Linux

                http://blog.csdn.net/guowenyan001/article/details/11060735

3.1 configure參數

        包含NDK、Lua_module模塊

        ./configure --add-module=../ngx_devel_kit-0.2.18/ --add-module=../lua-nginx-module-0.8.6/

四、驗證Nginx是否鏈接了libluajit-5.1.so.2

        ldd /usr/local/nginx/sbin/nginx | grep lua

五、第一個Nginx Lua代碼

5.1 Lua代碼

文件:nginx.conf

 

[plain]  view plain  copy
 
  1. location /test{  
  2.                 content_by_lua '  
  3.                         ngx.say("Hello world")  
  4.                         ngx.log(ngx.ERR, "err err")';  
  5.         }  

 

5.2 調用外部Lua腳本

文件:hello.lua

 

[plain]  view plain  copy
 
  1. ngx.say("Hello World")  

 

文件:nginx.conf

 

[plain]  view plain  copy
 
  1. location /test2{  
  2.                 content_by_lua_file conf/lua/hello.lua;  
  3.         }  

5.3 運行結果

 

 

參考資料:

        Ngx_lua使用分享:http://17173ops.com/2013/11/01/17173-ngx-lua-manual.shtml#toc7

轉載自:https://blog.csdn.net/guowenyan001/article/details/48250589


免責聲明!

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



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