Welcome! Log In Create A New Profile

Advanced

Re: lua possibilities/limitations

agentzh
February 13, 2011 11:12PM
On Sun, Feb 13, 2011 at 12:02 PM, Richard Kearsley
<Richard.Kearsley@m247.com> wrote:
> Hi Guys,
>
> I need a little help with the lua module. My ultimate aim is to import
> variables into nginx from outside source.
>

Your code below is totally wrong because you do not understand nginx
request phases well enough :)

1. Your content_by_lua always runs after any write-phase directrives
like "set" and "if" even if you put "set $limit_rate $myvar;" after it
in the config file.

2. Your content_by_lua for the /main location does not generate any
response bodies (using ngx.print or ngx.say in Lua). So you see the
empty response body on the client side.

BTW, your "add_header" directive runs in the output filter phase, so
your X-Test header gets the value set by your Lua code, which is
expected. But your X-Limit gets the old value because "set $limit_rate
$myvar" runs *before* $myvar gets the new value in Lua and $limit_rate
is still the old value. (For why "set" runs after your content_by_lua
code, see above).

FWIW, rewrite_by_lua and access_by_lua also run *after* those "set",
"if", "rewrite" directives provided by ngx_rewrite.

>
> Am I going about this in the right way? As I say, my ultimate aim is to set
> a whole bunch of nginx vars from outside...
>

For this purpose, rewrite_by_lua or access_by_lua will almost be
sufficient. But if you want to calculate variable values using
response headers (from ngx_proxy or ngx_fastcgi), then you need to
issue subrequests in content_by_lua before ngx_lua gets the
"output_header_filter_by_lua" directive implemented :)

Cheers,
-agentzh

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

lua possibilities/limitations

Richard Kearsley February 13, 2011 01:16AM

Re: lua possibilities/limitations

agentzh February 13, 2011 11:12PM

Re: lua possibilities/limitations

agentzh February 13, 2011 11:18PM

Re: lua possibilities/limitations

Eugaia February 14, 2011 05:38AM

RE: lua possibilities/limitations

Richard Kearsley February 14, 2011 06:50PM

Re: lua possibilities/limitations

agentzh February 14, 2011 11:32PM

Re: lua possibilities/limitations

Eugaia February 15, 2011 04:02AM

Re: lua possibilities/limitations

agentzh February 15, 2011 05:50AM

Re: lua possibilities/limitations

agentzh July 04, 2011 05:32AM

RE: lua possibilities/limitations

Richard Kearsley July 04, 2011 08:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 166
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