一、編譯安裝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
- location /test{
- content_by_lua '
- ngx.say("Hello world")
- ngx.log(ngx.ERR, "err err")';
- }
5.2 調用外部Lua腳本
文件:hello.lua
- ngx.say("Hello World")
文件:nginx.conf
- location /test2{
- content_by_lua_file conf/lua/hello.lua;
- }
5.3 運行結果
參考資料:
Ngx_lua使用分享:http://17173ops.com/2013/11/01/17173-ngx-lua-manual.shtml#toc7
轉載自:https://blog.csdn.net/guowenyan001/article/details/48250589