Giter Site home page Giter Site logo

lua-nginx-module's Introduction

Name

OpenResty - Turning Nginx into a Full-Fledged Scriptable Web Platform

Table of Contents

Description

OpenResty is a full-fledged web application server by bundling the standard nginx core, lots of 3rd-party nginx modules, as well as most of their external dependencies.

This bundle is maintained by Yichun Zhang (agentzh).

Because most of the nginx modules are developed by the bundle maintainers, it can ensure that all these modules are played well together.

The bundled software components are copyrighted by the respective copyright holders.

The homepage for this project is on openresty.org.

For Users

Visit the download page on the openresty.org web site to download the latest bundle tarball, and follow the installation instructions in the installation page.

For Bundle Maintainers

The bundle's source is at the following git repository:

https://github.com/openresty/openresty

To reproduce the bundle tarball, just do

make

at the top of the bundle source tree.

Please note that you may need to install some extra dependencies, like perl, dos2unix, and mercurial. On Fedora 22, for example, installing the dependencies is as simple as running the following commands:

sudo dnf install perl dos2unix mercurial

Back to TOC

Additional Features

In additional to the standard nginx core features, this bundle also supports the following:

Back to TOC

resolv.conf parsing

syntax: resolver address ... [valid=time] [ipv6=on|off] [local=on|off|path]

default: -

context: http, stream, server, location

Similar to the resolver directive in standard nginx core with additional support for parsing additional resolvers from the resolv.conf file format.

When local=on, the standard path of /etc/resolv.conf will be used. You may also specify arbitrary path to be used for parsing, for example: local=/tmp/test.conf.

When local=off, parsing will be disabled (this is the default).

This feature is not available on Windows platforms.

Back to TOC

Mailing List

You're very welcome to join the English OpenResty mailing list hosted on Google Groups:

https://groups.google.com/group/openresty-en

The Chinese mailing list is here:

https://groups.google.com/group/openresty

Back to TOC

Report Bugs

You're very welcome to report issues on GitHub:

https://github.com/openresty/openresty/issues

Back to TOC

Copyright & License

The bundle itself is licensed under the 2-clause BSD license.

Copyright (c) 2011-2019, Yichun "agentzh" Zhang (章亦春) [email protected], OpenResty Inc.

This module is licensed under the terms of the BSD license.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Back to TOC

lua-nginx-module's People

Contributors

agentzh avatar bakins avatar balusch avatar catbro666 avatar chaoslawful avatar chipitsine avatar chronolaw avatar cppcoffee avatar cubicdaiya avatar detailyang avatar dndx avatar doujiang24 avatar ghedo avatar jinglong avatar kindy avatar kingluo avatar liseen avatar lynch1981 avatar membphis avatar oowl avatar piotrsikora avatar rainingmaster avatar shrimp avatar spacewander avatar thibaultcha avatar tmthrgd avatar willmafh avatar xiaocang avatar zhuizhuhaomeng avatar zhuzhaoyuan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lua-nginx-module's Issues

How to use ngx.OK ngx.DONE ngx.AGAIN ngx.ERROR ?

In "Nginx API for Lua" -- "Core constants", there are 4 constants .
But there are no any infomation ahout how to use them.

So, how to use them ? Are they as same as NGX_OK/NGX_AGAIN/NGX_DONE/NGX_ERROR ??

How to handle gziped capture?

This may be more of a question than an issue. I want to feed the body of one capture into another ex:
local res2 = ngx.location.capture("/cap2?"..res1.body)
However res1.body was gziped by the origin server. Any idea how I can prevent the gzip of the body (a special Accept-Encoding header maybe) or unzip it using something like the gzio library on luaforge (http://luaforge.net/projects/gzio/)?

running nginx fails on luajit so after build

Hi.

$ export LUAJIT_LIB=/home/tom/Applications/LuaJIT-2.0.0.beta5/lib

$ export LUAJIT_INC=/home/tom/Applications/LuaJIT-2.0.0.beta5/include/luajit-2.0

$ ./configure --prefix=/home/tom/Applications/nginx-0.8.53 --add-module=/home/tom/Downloads/ngx_devel_kit --add-module=/home/tom/Downloads/lua-nginx-module

$ make -j

$ make install

$ /home/tom/Applications/nginx-0.8.53/sbin/nginx

nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory

$

ngx.location.capture header inheritance

Hi
I spoke with you over nginx mailing list yesterday
I was having problem where the request headers weren't getting passed through on a sub-request
Anyway, I got to the bottom of it:
Headers ARE passed if 'method' is left unset (it defaults to GET I assume)
But if method IS set, to ngx.HTTP_GET or ngx.HTTP_HEAD (I didnt test POST) then they are not passed through

Hope this helps & keep up the good work

stack overflow when requiring a luarocks module

I've got something like the following

-- test.lua
local xxx = require("xxx")

-- xxx.lua
module("xxx", package.seeall)
local yyy = require("yyy")

-- yyy.lua
module("yyy", package.seeall)
local rocks = require("luarocks.loader")
local md5 = require("md5")

When I do this, I get the following error:

2011/04/05 21:59:32 [error] 38737#0: *93 lua handler aborted: runtime error: /usr/local/share/lua/5.1/luarocks/path.lua:244: stack overflow, client: 127.0.0.1, server: localhost, request: "GET /ex?name=test&count=1 HTTP/1.1", host: "localhost:8080"

The yyy.lua module works fine from a non-nginx script.

Thanks!

global functions "disappear" after one invocation

Hi,

I'm experiencing a very strange behavior of 0.2.1rc2 with nginx 1.0.5 . Issuing a first request that invokes lua code works fine. However, repeating the exact same request a 2nd time fails due to calling a function that is now nil (it wasn't nil in the first invocation). The function is originally defined in a file that is "require"d by the lua file that is called by nginx (via rewrite_by_lua_file) . Oddly, when setting "lua_code_cache off" everything works ok!
Is this a known problem?

Setting subrequest variables

Hi,

Are you planning on implementing being able to set subrequest variables?

e.g.

ngx.location.capture {url, {args={...}, vars={...}}}

Unless I'm mistaken, you can't safely do multiple e.g. memcache lookups asynchronously by setting e.g. $memc_key from Lua because you'd have to share the variables with each subrequest, but if you do that, then you're going to set the variables for one and all the subrequests are going to have the same ones (as the last one set).

You can of course parse them as arguments, but then you have to unescape them before you send them to memcached.

You might also want to consider giving the option to copy the parent request's variables, as well as zeroing them and sharing them.

I'm a bit busy to do it right now, but if you've not done it later on, I'll do it.

Cheers,

Marcus.

compile error with nginx 1.0.5 on Ubuntu natty

The following error happens when building lua-nginx-module with nginx 1.0.5:

../chaoslawful-lua-nginx-module-188cd41/src/ngx_http_lua_script.c: In function ‘ngx_http_lua_compile_complex_value’:
../chaoslawful-lua-nginx-module-188cd41/src/ngx_http_lua_script.c:159:18: error: ‘n’ may be used uninitialized in this function
make[1]: *** [objs/addon/src/ngx_http_lua_script.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory `/home/hydra35/Downloads/nginx-1.0.5'
make: *** [build] Error 2

Configure parameters:

./configure --add-module=../simpl-ngx_devel_kit-bc97eea --add-module=../chaoslawful-lua-nginx-module-2be9349

System and gcc version:

$ lsb_release  -a
Distributor ID: Ubuntu
Description:    Ubuntu 11.04
Release:    11.04
Codename:   natty

$ gcc --version
gcc.real (Ubuntu/Linaro 4.5.2-8ubuntu4) 4.5.2

luarocks

Is it possible to make it works with luarocks ?
if yes, how ?
i can require luarocks itself require("luarocks.require"), but i call another library i installed with luarocks i got some errors.

Still can't get nginx_lua_module works

Hello, thanks for the lua module contributions for Nginx. I might have 'unknown directive' issue for "set_by_lua" in the nginx.conf file after I compiled all relative modules under follow the steps in the official post. The Nginx + Lua_module seemed complied without any error, I even can see all the linking objects during compiling:
.....
objs/addon/src/ngx_http_lua_module.o
objs/addon/src/ngx_http_lua_headers.o
objs/addon/src/ngx_http_lua_directive.o
objs/addon/src/ngx_http_lua_hook.o
objs/addon/src/ngx_http_lua_util.o
objs/addon/src/ngx_http_lua_cache.o
objs/addon/src/ngx_http_lua_conf.o
objs/addon/src/ngx_http_lua_contentby.o \ ...

this is the part of block I used for testing purpose in nginx.conf:

location /inline_concat {
# MIME type determined by default_type:
default_type 'text/plain';

            set $a "hello";
            set $b "world";
            # inline lua script
            set_by_lua $res "return ngx.arg[1]..ngx.arg[2]" $a $b; # --> stop here.
            echo $res;
    }

Any idea?

Regards.

Bug in ngx.header[] when setting new Headers

Hi,
i found some weird behaviour in ngx.header[] when i try to set a new header. When trying to set two different headers which have the same letter(s) in the beginning, one gets overwritten when setting a one-value-header. If a multiple-value header is set, the tables get mixed up... like:

ngx.header["foox"] = "foo"
ngx.header["fooy"] = "bar"

the second header won't be written, but the value of the first changed to "bar". ngx.header[] = {} has the same behaviour, but there, the tables get mixed up.

I wrote 2 tests for nginx-test which fail in my setup (nginx 1.0.2. and the latest lua-nginx-module from here):

016-resp-header.t:

=== TEST 13: names are the same in the beginning (one value per key)
--- config
    location /lua {
        content_by_lua '
            ngx.header["Foox"] = "barx"
            ngx.header["Fooy"] = "bary"
            ngx.send_headers()
        ';
    }
--- request
    GET /lua
--- response_headers
Foox: barx
Fooy: bary
--- response_body



=== TEST 13: names are the same in the beginning (multiple values per key)
--- config
    location /lua {
        content_by_lua '
            ngx.header["Foox"] = {"conx1", "conx2" }
            ngx.header["Fooy"] = {"cony1", "cony2" }
            ngx.send_headers()
        ';
    }
--- request
    GET /lua
--- response_headers
Foox: conx1, conx2
Fooy: cony1, cony2
--- response_body

I will try to take a look into it for myself this evening - hope i can contribute a solution :-)

Accessing nginx reactor core via lua module?

This is more of a question than an issue...

I've been playing with the idea of making an nginx module to route requests via a 0MQ socket, instead of the regular http proxy method: https://github.com/igrigorik/zeroconf-router/tree/master/nginx

The above example is minimal, at best, but it illustrates the basic functionality. By leveraging XREQ/XREP sockets, we can decouple the backend from frontend server and skip on the entire configuration step. The current gotcha, and the reason for my questions is: as implemented in that example, the ZMQ socket read/writes are done outside of the main nginx reactor, which will obviously cause problems. 0MQ does allow us to get an FD, so I'm wondering if it would be somehow possible to feed that FD into the main reactor loop via the lua module? And then get notifications of incoming messages...

Not one to one, but an example of 0MQ + event loop: https://github.com/Neopallium/lua-zmq/blob/master/examples/ev_subscriber.lua

Thoughts, ideas, comments? :-)

Multiple parallel subrequests

Right now location capture is done in the background, but you're limited to issuing one request at a time. If you need to pull data from multiple sources, your page is as slow as the sum of all subrequests, but would be reduced to just the slowest if they could be issued in parallel.

If a table were passed to location.capture like this, then it would respond with an identical table of res objects.

res = ngx.location.capture({ "http://this/...", "http://that/...", "http://..." })
ngx.print( res[0].body, res[1].body, res[2].body )

Or it may be easier to use a separate function (e.g. capture_multi).

Quitting a Request when a Subrequest is started.

Hi,
the topic is a bit misleading, but here is what i mean exactly:

I can hit a subrequest via ngx.location.capture() for the uri the normal request is meant for (ngx.var.uri).
Then i have e.g. a res-variable which contains res.header, res.body and res.status.

Then i can cange the contents of the variables and e.g. write the headers back to ngx.header[] ...and output the res.body via ngx.print(res.body)

BUT how can i stop the original request from being processed at all? (flush or eof won't do this, i think?)

The baseline for the explanation would be: I want to catch a request, change it, do a subrequest with the information gathered and then output the information received by the subrequest (i don't want the original request to be executed at all!)?

Is there any way to achieve this behaviour? - My attemps when trying to force the stop of the request fail...

Here's a example code what i would like to do:

if ngx.is_subrequest == false then

    res = ngx.location.capture(ngx.var.uri)

    for i,j in pairs(res.header) do
        ngx.header[i] = j
    end

     ngx.print(res.body)

--     ngx.flush()
--     ngx.eof()

end

Setting response headers

I'm having problems setting response headers. I've tried

ngx.set_header("Content-Type","text/html")
ngx.header.content_type = "text/html"
ngx.header["Content-Type"] = "text/html"

The Content-Type header is not set. Here is my location:

    location /identity {
        default_type text/html;
        lua_need_request_body on;
        client_max_body_size 10k;
        client_body_in_single_buffer on;
        content_by_lua_file /Users/william/biblegateway/identity/server/router.lua;

I've tried setting the headers both before and after any other response was generated, but there is nothing in the response.

FastCGI problem with subrequests and POST-data

At first: I still don't know, where the error is coming from exactly.

When doing a post-request with data to php-scripts via ngx.location.subrequests the fastcgi processing has a timeout (504 for the client then) like:


2011/06/21 14:19:41 [error] 12165#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 10.100.20.192, server: localhost, request: "GET /test.php HTTP/1.1", subrequest: "/test.php", upstream: "fastcgi://unix:/var/run/php-fpm/php-fpm.sock:", host: "10.20.10.216:1337"

There is a Ubuntu 10.04 32bit on a VMware Server, a Ubuntu 11.04 32bit on a VMware Server, a ArchLinux (up-to-date) 32bit on a VMware Server and a ArchLinux (up-to-date) 64bit on my laptop as a local installation.

The machines all have nginx 1.0.4 and the latest lua-nginx-module and ngx_devel_kit (even did a new clone - and no pull)

!!! The weird thing is: The error occurs on all machines, but not on my local ArchLinux. And the ONLY occur when lua-code is active - without everything works normal.

To make it easier i only describe the 32bit (vm) and 64bit (local) ArchLinux machines:

VM:
2.6.39-ARCH i686 GNU/Linux
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
luasocket 2.0.2-5 (from package repository - not luarocks)
gcc version 4.6.0 20110603 (prerelease) (GCC)

Local:
2.6.39-ARCH x86_64 GNU/Linux
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
luasocket 2.0.2-5 (from package repository - not luarocks)
gcc version 4.6.0 20110603 (prerelease) (GCC)

And on both machines i have nginx-1.0.4 and even did compile it with lua-nginx-module and ngx_dev_kit as a new user with fresh cloned repositories (only a few hous ago)

Here's the lua-code

    function set_request_method()
        local val = ngx.var.request_method
        if val == "GET" then
            return ngx.HTTP_GET
        elseif val == "HEAD" then
            return ngx.HTTP_HEAD
        elseif val ==  "PUT" then
            return ngx.HTTP_PUT
        elseif val == "POST" then
            return ngx.HTTP_POST
        elseif val == "DELETE" then
            return ngx.HTTP_DELETE
        end
    end

    res = ngx.location.capture( or ngx.var.request_uri, { method = set_request_method(), body =
"foo"})

        for i,j in pairs(res.header) do
            ngx.header[i] = j
        end

        ngx.status = res.status

        ngx.print(res.body)

        ngx.exit(res.status)
        ngx.flush()

The php-script:

<?php
echo @file_get_contents('php://input');
?>

When i access the php-script on the local Archlinux64bit, it shows "foo" in the client, like expected - when i access it on the VMware Archlinu32bit, i get the 504-timeout and the fcgi-error in the logs :-(

I don't know what could cause this - The machines are theoretically the same! (Besides one is 32bit and one 64bit), all the configuration-files are the same, too.

The Debug-logs when accessing the test.php-script:
The local installation, where everything works: http://pastebin.com/XvE9zKWA
The vmware server, where it fails: http://pastebin.com/9fFhYuUZ

Thanks, moody

ngx.exec and ngx.redirect

I have a dev server which is ubuntu 10.10 64 bits.
I have installed nginx 1.0.5 with lua-nginx-module and lua-redis-parser.

I have the same setup on another dev server which run centos 5.4.

On both server I run this piece of lua code.

content = ngx.location.capture("/content", {args = ngx.var.args});
if content.status == 302 or content.status == 301 then
-- ngx.redirect(content.header["Location"], content.status);
ngx.exec(content.header["Location"]);
end

The url contained in content.header["Location'] is like "/user/redirect?test=1"
On the first server, it run without problem when ngx.redirect() is used but created a "400 Bad Request" when ngx.exec() is used
On the second server, ngx.redirect() create a "400 Bad Request" and hang when ngx.exec() is used.

In both case I use the latest version of nginx and lua-nginx-module from git.

Any way I can figured out why the behavior is different and why it doesn't work overall?

Thanks for your help.
Olivier

note on globals

You say "WATCH OUT: Globals WON'T persist between requests" - thats true, but if you really want them to you can assign them to _G directly and they will persist.

I think it is probably nicer to have an explicit Lua initialisation config though...

asynchronous request body reading

It is possible to do like this:

ngx.read_request_body(function (data)
if XXX then
return ngx.OK -- NO more data is require
else
return ngx.AGAIN -- Call me again when more data income
end
end)

Parameter to not cache lua script

Hi, this is a feature request.

As I am starting to use the module more seriously, I find it painful to have to restart nginx everytime I modify a lua script when using the module with content_by_lua_file.

In Apache mod_lua, they have the following directive :
LuaCodeCache stat
LuaCodeCache forever
LuaCodeCache never

Maybe having something like that would make things easier for people like me who develop Lua websites on the fly...

Do you think this could be added to the module ?
Thank you.

Issues with subrequests in Lua 5.1.4

Hi,

When using Lua 5.1.4 to do subrequests (e.g. ngx.location.capture() -> memc_pass), after the first or second subrequest, I've found that that I've had a host of problems, including:

  • segfaulting
  • 'attempt to call a nil value' errors
    and (in versions around 2.0 - 2.1.7/8 of ngx_lua)
  • 'attempt to yield across metamethod/C-call boundary' errors

As mentioned in another post, I've been doing a lot of hacking, and didn't do any checking without my code compiled-in. However, when I switched to LuaJIT, these issues went away.

I don't know how interested you are in supporting 5.1.4 since you're using JIT, but just in case you were, I thought I'd pass it on. I'm afraid I haven't got the time to look into it in any more depth myself right now.

Cheers,

Marcus.

Getting ALL request headers

hi, i just implemented the code to be able to get really ALL request headers which are available via a table. Setting a new request header is available, too.

My problem is, that i was not able to implement it the way you did the other methods ( with __index and __newindex). Somehow either the parameters for getting or for setting were not working

i implemented it with extra functions for now ngx.req_header_set("key", "value") and ngx.req_header_get() (which returns a table)

the changes are here: https://github.com/moodydeath/lua-nginx-module/compare/master...req_header

there is still some work to do (error with no arguments, etc) and i think som request-headers have to be changed otherwise by hard-coded variables in nginx (content-length)

the other thing is, that - even if i tried a lot of things - i am not able to do it the way with __index / __newindex.

luajit segmentation fault

I am using the lua nginx module successfully with the standard lua interpreter. I tried it with luajit version 2.0 beta 5, but nginx crashes with a segmentation fault. What information can I provide to help resolve this issue? I'm running it on Snow Leopard Server. I'll try it with other versions of luajit to see if I can narrow down the problem. What versions of luajit have you tested with? Which platforms?

Passing a table to ngx.print() causes segfault

Hi guys,

I believe that recent versions of ngx_lua have the problem that if you pass a table to ngx.print() they segfault. I say believe, because the builds I run have a lot of code that I've been hacking recently, so there may be a bug in that, but I tried back to version 2.0 of ngx_lua and it went away. It may not be for every structure of table (I've not really tried more than one), but it segfaults for at least some.

I've tested in both the latest versions of standard and JIT Lua as of today. The bug appeared some time not long after version 2.1.7 I think - I've not done extensive testing to pin it down to an exact version.

Just thought I'd let you know.

Cheers,

Marcus.

Fails to compile on MAC

.
.
.
-Wl,-E -L/opt/local/lib -lm -llua -L/opt/local/lib -lpcre -lssl -lcrypto -lz
ld: unknown option: -E
collect2: ld returned 1 exit status
make[1]: *** [objs/nginx] Error 1
make: *** [build] Error 2

ld on the MAC doesn't have a -E Removing the -E in the config breaks the build.

Server name in subrequest

Is it possible to use ngx.location.capture to make a subrequest to a location within a different server directive from the original request? If not, is this a limitation of nginx's subrequest capabilities or is it possible to modify this module allow this?

I'd like to do something along the lines of:

ngx.location.capture('/path', { host = 'example.com' })

Where example.com matches a server_name directive in the config.

Thanks!

Accessing querystring vars

I actually have two questions related to querystring vars, those are just to start a discussion :)

First I was wondering why you prefix the variables with 'arg_' when they are accessed with ngx.var["arg_num"] for example. Is this the way nginx stores them internally ? I thought it could make more sense to just use ngx.var["num"], this way no need to prefix variable names with "arg_". I realize this is a BC break though, so maybe having ngx.vars["num"] or like with PHP, ngx._get["num"] and ngx._post["num"] to make a difference between variables from GET, POST (and COOKIE, ENV actually...).

Then, I was wondering if there was a way to deal with request vars with the same name, for example : ?num=1&num=2
IIRC, mod_lua from Apache 2.4 converts the variable to a table in this case. PHP on the other side insist on having brakets like this : ?num[]=1&num[]=2 which can be handy because it also works with num[x]=1&num[y]=2 to create an associative array.

Maybe all of this could be done on the Lua side if I parse ngx.var["request_uri"] or the body. I just thought it could be easier if it was done in the module directly.

Memory allocation

Hi,

I've been fishing around in the lua code a bit more, and it appears to me that memory allocation in ngx_lua as you currently have it used free() and realloc() for memory allocation, rather than using ngx_free() and ngx_palloc().

Is there a reason for this? Would it not be better to use a function that wrapped around ngx_palloc?

Cheers,

Marcus.

Positional (numeric, match group) variables

Is there a way to access $1, $2 and such from lua?

I tried the obvious ngx.var[1] and ngx.var["1"] but they didn't work.

One workaround is to set them to other variables: set $arg1 $1; but it adds unnecessary clutter.

Function to set headers_out

Hi (again),
I would like to know if you plan to add a way to set headers_out, for example header("Content-type : text/html") or ngx.request.headers_out["Content-type"] = 'text/html' ?
And maybe a way to access the request directly ?
Maybe the module is not planned to be used that way, please let me know.
Thanks.

i can't get ngx.var.http_cookie

--conf/test.lua
ngx.print(ngx.var.content_type);--error
ngx.print(ngx.var.http_cookie);--error
ngx.print(ngx.var.remote_addr);--success

不知道什么原因,请指教!

编译错误

编译时发生如下错误:
ake -f objs/Makefile
make[1]: Entering directory /root/nginx-0.7.65' gcc -c -DNDK -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I /root/nginx-module/simpl-it-ngx_devel_kit-7ccc46d -I /root/nginx-module/simpl-it-ngx_devel_kit-7ccc46d/src -I /root/nginx-module/simpl-it-ngx_devel_kit-7ccc46d/src/auto -I src/mail \ -o objs/addon/src/ngx_http_lua_util.o \ /root/nginx-module/lua-nginx-module/src/ngx_http_lua_util.c gcc -c -DNDK -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs -I src/http -I src/http/modules -I /root/nginx-module/simpl-it-ngx_devel_kit-7ccc46d -I /root/nginx-module/simpl-it-ngx_devel_kit-7ccc46d/src -I /root/nginx-module/simpl-it-ngx_devel_kit-7ccc46d/src/auto -I src/mail \ -o objs/addon/src/ngx_http_lua_cache.o \ /root/nginx-module/lua-nginx-module/src/ngx_http_lua_cache.c /root/nginx-module/lua-nginx-module/src/ngx_http_lua_util.c: In function ‘ngx_http_lua_var_get’: /root/nginx-module/lua-nginx-module/src/ngx_http_lua_util.c:320: 错误:提供给函数 ‘ngx_http_get_variable’ 的实参太少 make[1]: *** [objs/addon/src/ngx_http_lua_util.o] 错误 1 make[1]: *** 正在等待未完成的任务.... make[1]: Leaving directory/root/nginx-0.7.65'
make: *** [build] 错误 2

环境:
CentOS 5.3
nginx-0.7.65
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
ReadMe文件中所说的三个模块均是从github上下载的最新tar包

Request: Later phase handler support

Hi! I'm actively using a number of your plugins with great results - thank you!!! I'm now running up against some new potential use cases and I'm curious if having the functionality to execute lua code in the later phase handlers would be appropriate. Here's what I'm after:

I perform a number of dynamic redis queries via a pipeline within the access_by_lua handler. This works great! However, I would also like to save information, update Zset scores within redis which does not necessarily need to happen at this layer. I'm curious how much more efficient the entire process would be if I could save info back into redis via a log_by_lua handler that happened late in the nginx phases (like NGX_HTTP_LOG_PHASE) and did not interfere before my other dynamic code fires.

I know this functionality doesn't exist today, but curious if the above is sound logic and whether adding support for more lua_handlers (like log_by_lua*) might be feasible?

Again, big thumbs up for all the contributions to the nginx community thus far :)

Passing new headers to location.capture?

I would like to pass arbitrary headers to requests made through the location.capture mechanism, but looking at the source it appears that the set_content_length_header method is what handles all of the header duplication from the parent request. Are there any plans to add this functionality?

weird pattern matching behaviour

Hello
In one script called but ngx_lua, i'm doing some pattern matching, but it does not behave as expected. I'm launching this expression : string.match('http://www.example.com/iop','http://.*\.?example.com') but it returns nil
any idea ?

2 Subrequest calls when using access_by_lua, ngx.exec and echo_location

Hello!
I am using the following configuration.
location /sub {
proxy_pass http://origin-server/;
}
location /p{
echo_location /sub;
}
location / {
access_by_lua '
ngx.exec("/p")
';
}
For each client request the origin server gets two requests from the nginx. Also, the client gets two copies of the response:

curl http://localhost/

Test server.
Test server.

configuration:
#./sbin/nginx -V
nginx: nginx version: nginx/1.0.2
nginx: built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)
nginx: configure arguments: --add-module=../agentzh-echo-nginx-module-4b30897 --add-module=../chaoslawful-lua-nginx-module-1ab26d0 --with-debug

#uname -a
Linux android20 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux

cat /etc/issue
Ubuntu 10.04.1 LTS \n \l

how to use require?

i use require like:
local xxx = require('xxx')
but,it also haven't to work.

--test.lua
function a()
ngx.print("test.lua");
end;

a();

--concat.lua
local test=require("test");


at the first request,it print:
test.lua

and,the next time,have nothing print;

Compiling on GCC 4.6.0

I'm not able to compile nginx (1.0.1) with the lua-nginx-module on ArchLinux which has GCC 4.6.0.

It's the same problem as it was in nginx 1.0.0 itself with this gcc-version before. A workaround was and still is to remove the -Werror flag from objs/Makefile after configuring.

(For nginx 1.0.0 and gcc Igor Sysoev posted a solution on the mailinglist - don't know if it would help somehow... http://forum.nginx.org/read.php?2,194033 )

This is the error:

/home/moody/Development/Sources/lua-nginx-module/src/ngx_http_lua_hook.c: In function ‘ngx_http_lua_ngx_req_header_set_helper’:
/home/moody/Development/Sources/lua-nginx-module/src/ngx_http_lua_hook.c:2203:34: error: variable ‘ctx’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors

make[1]: *** [objs/addon/src/ngx_http_lua_hook.o] Error 1
make[1]: Leaving directory `/home/moody/Development/Sources/nginx-1.0.1'
make: *** [build] Error 2

Allow multiple rewrite_by_lua_file

Hi:

Currently, rewrite_by_lua_file cannot be used more than once. If this directive appears twice in one context, say location context, nginx -t will report duplicate directive. If it is used in different contexts, say location and http context, only the smaller scope get executed.

So I am wondering if we can have more than one rewrite_by_lua_file. The primary reason is that separate code into different files enhance code readability and ease maintenance. Otherwise, we've to put all the rewrite stuff in one big file and this decrease the overall usability of nginx-lua module in complex environments.

Or any suggestion on how to achieve this without multiple files?

lua_require

Hello

where should i put lua_require

http {
    lua_package_path './?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/usr/local/lib/lua/5.1/?.lua;/usr/local/lib/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;
/usr/share/lua/5.1/?/init.lua;/home/deploy/src/www/lib/?.lua';
    lua_require 'some_library';

I put it there, but i got this error : [emerg]: unknown directive "lua_require" in /usr/local/etc/nginx/nginx.conf:22

Should i put this directive somewhere else ?

lua_package_path and lua_package_cpath at server level

Hi guys,

I'm finally getting into some ngx_lua scripting for Tagmata, so might be sending some patches to you soon.

One thing I just thought about - currently the path and cpath for searching for lua packages is at the http level. However, I can see situations where it might be really useful to be able to define it at the server level - e.g. if you're writing your own modules to be included in lots of pages on one site, but you have another site that you're doing the same on, and you don't want them to share those modules and want to completely isolate them from one another.

Do you have any plans to add this facility? Do you think it would be a relatively simple thing to do, or are there complications that you know of (e.g. problems with modules loading sub-modules which might not be the same between calls).

Cheers,

Marcus.

Deleting Set-Cookie response header

ok, first - don't try to find a sense in this code - but it does not behave as it is expected:

i have a php-script which is used via fastcgi in nginx and will only execute this:

<?php
setcookie("TestCookie1", "foo");
setcookie("TestCookie2", "bar");

phpinfo();
?>

When using rewrite_by_lua_file with this code something unexpected happens:

if ngx.is_subrequest == false then

        ngx.header["Set-Cookie"] = {}
        res = ngx.location.capture(ngx.var.uri)

        for i,j in pairs(res.header) do ngx.header[i] = j end

        ngx.send_headers()
        ngx.print(res.body)

end

Normally i thought that the "for .. pairs"-part will write all response-headers from the subrequest into the ngx.header-table again. but in the Set-Cookie header only "TestCookie2" is received by the client which starts the request...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.