nginx lua 01

  1. content_by_lua 

    location /lua {
      content_by_lua '
        ngx.say("hello content_by_lua");
      ';
    }
  


    2. content_by_lua_file
        location /lua {
            content_by_lua_file lua/test.lua ;
        }


        #这个文件必须是nginx的--prefix目录下才行。 
        ├── client_body_temp [error opening dir]
        ├── fastcgi_temp [error opening dir]
        ├── html
        │   ├── 50x.html
        │   └── index.html
        ├── lua
        │   └── test.lua
        ├── proxy_temp [error opening dir]
        ├── sbin
        │   └── nginx
        ├── scgi_temp [error opening dir]
        └── uwsgi_temp [error opening dir]







 

 

2. lua_package_path

    1. 指定位置
    lua_package_path "/usr/local/etc/openresty/lua/?.lua;;";

    2. location配置
    location / {
        content_by_lua_file lua/test.lua;
    }

    3. cat /usr/local/etc/openresty/lua/test.lua
        local _M = {}


        function _M:new()        -- 不能有local,不然外面找不到这个方法
        ngx.say("this is t")
        end


        return _M   


     4.  cat test.lua

              local t = require "test";
              t:new();
              ngx.say("lua hello");       





# lua_package_path 就是为了require用的。

         

 

 

 

posted @ 2019-06-06 12:52  追求那份真  阅读(209)  评论(0编辑  收藏  举报