How to use content_by_lua and proxy_pass together ?

6,356 views
Skip to first unread message

Peter G

unread,
Jun 25, 2014, 8:21:10 AM6/25/14
to openre...@googlegroups.com
Hi

Basically i want to do some safety check before doing proxy_pass

For example, Lets say I want to block all the PUT methods.

So my code is like this

     location / {

                     content_by_lua '
                                                --Blah blah
                                                if my_condition then
                                                   res = ngx.location.capture("/gohere")
                                                   ngx.say(res.body)
                                                   return
                                            ';

                     proxy_pass http://myupstream;
     }


AS you can see, I want to first check for some condition and go to alternate locataion which handles say errors.  Only in else condition I want to do proxy_pass.

I am seeing that Irrespective of my condition, IT is always doing proxy_pass :(

What am i missing here ?

tomi....@gmail.com

unread,
Jun 25, 2014, 8:30:14 AM6/25/14
to openre...@googlegroups.com

Robert Paprocki

unread,
Jun 25, 2014, 1:09:36 PM6/25/14
to openre...@googlegroups.com
Hi,

From the Ngxinx Lua API documentation:

Do not use this directive and other content handler directives in the same location. For example, this directive and the proxy_pass directive should not be used in the same location.

You should use access_by_lua instead of content_by_lua.
--
You received this message because you are subscribed to the Google Groups "openresty-en" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openresty-en...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lord Nynex

unread,
Jun 25, 2014, 8:57:23 PM6/25/14
to openre...@googlegroups.com
This is not relevant. 


--

Peter G

unread,
Jun 26, 2014, 6:58:25 AM6/26/14
to openre...@googlegroups.com
If i use access_by_lua will it not call proxy_pass ?

Robert Paprocki

unread,
Jun 26, 2014, 7:04:35 AM6/26/14
to openre...@googlegroups.com
See http://wiki.nginx.org/Phases

access_by_lua sits in the access phase; your lua code will run, and if
the transaction doesn't quit, it will get passed down to the next phases
(eventually the content phase, where proxy_pass sits). The lua code
doesn't call proxy_pass, that gets handled by the nginx worker itself.

If you don't want to proxy_pass if you meet a given condition, you can
ngx.say() your capture, then ngx.exit(200) to stop transaction
processing (instead of the return you have now)

On 06/26/2014 03:58 AM, Peter G wrote:
> If i use access_by_lua will it not call proxy_pass ?
>
> On Wednesday, June 25, 2014 10:39:36 PM UTC+5:30, rpaprocki wrote:
>
> Hi,
>
> From the Ngxinx Lua API documentation:
>
> Do not use this directive and other content handler directives in
> the same location. For example, this directive and the proxy_pass
> <http://wiki.nginx.org/HttpProxyModule#proxy_pass> directive should
>> send an email to openresty-en...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout
>> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "openresty-en" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to openresty-en...@googlegroups.com
> <mailto:openresty-en...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages