Welcome! Log In Create A New Profile

Advanced

Re: ngx_lua post data error/bug?

Nginx User
October 22, 2011 02:32AM
On 22 October 2011 04:25, agentzh <agentzh@gmail.com> wrote:
> On Sat, Oct 22, 2011 at 3:43 AM, Nginx User <nginx@nginxuser.net> wrote:
>>
>> Testing shows that the error is generated because of the
>> 'dofile("/etc/nginx/regex_rules.lua")' line.
>>
>
> Lua's "dofile" builtin is implemented as a C function in both Lua 5.1
> and LuaJIT 2.0. And when you call ngx.location.capture or ngx.exec or
> ngx.exit or ngx.req.read_body or something like those in the
> regex_rules.lua, it'll effectively initiate a coroutine yield and that
> yield will run across C function boundary, which is disallowed.
>
> I think it's more efficient to use Lua modules and the "require"
> builtin because dofile will load the .lua file from disk at *every*
> request and it's quite costy while "require" will only load the .lua
> module file only once unless lua_code_cache is turned off. Here is an
> example,
>
>    -- regex_rules.lua
>    module("regex_rules", package.seeall)
>    function check()
>        ngx.req.read_body()
>        -- other processing goes here...
>    end
>
>    # nginx.conf
>    lua_package_path "/path/to/regex_rules.lua's-parent-directory/?.lua;;"
>    server {
>        location /foo {
>             access_by_lua '
>                 local regex_rules = require "regex_rules"
>                 regex_rules.check()
>             ';
>             # content handler config goes here...
>        }
>    }
>
> BTW, compatibility with Lua 5.2 is not maintained by ngx_lua (yet).

Magic ... Works perfectly.

You are a legend!

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

ngx_lua post data error/bug?

Nginx User October 21, 2011 02:08PM

Re: ngx_lua post data error/bug?

Nginx User October 21, 2011 03:44PM

Re: ngx_lua post data error/bug?

agentzh October 21, 2011 09:26PM

Re: ngx_lua post data error/bug?

Nginx User October 22, 2011 02:32AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 223
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready