请问ngx.location.capture的使用方法

862 views
Skip to first unread message

kobeng

unread,
Oct 6, 2012, 4:46:55 AM10/6/12
to open...@googlegroups.com
hi
   ngx.location.capture 只能调用vhost内部location的uri,如果我想调用外部的uri的话,那么我该使用哪个方法呢?

   希望还是像
ngx.location.capture非阻塞的请求方式。

smallfish

unread,
Oct 6, 2012, 7:02:03 AM10/6/12
to open...@googlegroups.com
外部的请求可以用:https://github.com/liseen/lua-resty-http
--


2012/10/6 kobeng <benw...@gmail.com>
hi
   ngx.location.capture 只能调用vhost内部location的uri,如果我想调用外部的uri的话,那么我该使用哪个方法呢?

   希望还是像
ngx.location.capture非阻塞的请求方式。

kobeng

unread,
Oct 6, 2012, 7:33:48 AM10/6/12
to open...@googlegroups.com
谢谢 鱼哥......

kobeng

unread,
Oct 6, 2012, 7:56:07 AM10/6/12
to open...@googlegroups.com
nginx 1.2.3编译时出错了

--add-module=/usr/local/src/nginx-1.2.3/debian/modules/lua-resty-http \
             >config.status.full
make: *** [config.status.full] 错误 1
dpkg-buildpackage: 错误: debian/rules build 提供错误退出状态 2




On Saturday, October 6, 2012 7:02:05 PM UTC+8, smallfish wrote:

kobeng

unread,
Oct 6, 2012, 8:12:33 AM10/6/12
to open...@googlegroups.com
The quickest way may be just use ngx_proxy + ngx.location.capture?

用这种方式可行不?

agentzh

unread,
Oct 6, 2012, 12:26:38 PM10/6/12
to open...@googlegroups.com
Hello!


在 2012年10月6日星期六,kobeng 写道:
nginx 1.2.3编译时出错了

--add-module=/usr/local/src/nginx-1.2.3/debian/modules/lua-resty-http \
             >config.status.full
make: *** [config.status.full] 错误 1
dpkg-buildpackage: 错误: debian/rules build 提供错误退出状态 2

 
lua-resty-http 是 Lua 库,并不是 nginx C 模块。直接在你的 Lua 代码里 require 它就可以了。

Best,
-agentzh
Message has been deleted

kobeng

unread,
Oct 7, 2012, 3:51:13 AM10/7/12
to open...@googlegroups.com
章老师 这个部分有无有计划整合在nginx lua模块里面呢?

如果用ngx.location.capture 请求 同一个host里面的proxy pass,效果是不是一样非阻塞的?

agentzh

unread,
Oct 7, 2012, 3:21:43 PM10/7/12
to open...@googlegroups.com
Hello!

2012/10/7 kobeng <benw...@gmail.com>:
> 章老师 这个部分有无有计划整合在nginx lua模块里面呢?
>

lua-resty-* 库都是独立于 ngx_lua 模块的。我不可能把 lua-resty-* 整合进 ngx_lua 里面去。不过包含进
ngx_openresty 软件包是可能的,事实上 ngx_openresty 已经包含了 lua-resty-mysql,
lua-resty-memcached, lua-resty-redis, lua-resty-dns, lua-resty-upload,
和 lua-resty-string.

lua-resty-http 目前的状态还没达到包含进 ngx_openresty
的水平,我打算对它进行扩展和重构,或者另外再搞一个实现,然后再包含进 ngx_openresty :)

> 如果用ngx.location.capture 请求 同一个host里面的proxy pass,效果是不是一样非阻塞的?
>

所有由 ngx_lua 提供的 Lua API 都是非阻塞 I/O,自然也包括 ngx.location.capture :) 阻塞总是不可接受的。

Best regards,
-agentzh

Wendal Chen

unread,
Oct 7, 2012, 8:09:21 PM10/7/12
to open...@googlegroups.com
期待agentzh 对lua-resty-http的重构(重写)

-agentzh




--
Wendal Chen
GuangDong China
330.gif

Lance

unread,
Oct 7, 2012, 10:17:31 PM10/7/12
to open...@googlegroups.com
hi agentzh,

这里有一个之前我就注意到过,后来忘掉的 lua-resty-string,前两天就为了实现 random strong 费了半天力气,今天看到这里已经有了。

在它的页面 https://github.com/agentzh/lua-resty-string 没有使用文档,只有一些例子,想看有什么功能还得去翻源码,或者从例子里猜。

另外 lua-resty-* 系列,能否有一个总的文档,甚至 openresty 发行包的总体功能说明文档,指导用户去哪里找相关的功能呢?

对了,还有两个我最近一直在纠结的功能,类似 php 的 explode 和 str_replace,基于纯字符串而不是正则表达式的字符串切分和替换,这个在实际使用中我觉得比正则的更加常用。我自己做了一些实现(前两天那些邮件大多与此有关),但总感觉性能不太满意,你看看是否可能扩展在这个包里面呢?

建议和意见都在这里了,您将就着看,嘿嘿。

Lance


2012/10/8 agentzh <age...@gmail.com>
-agentzh

agentzh

unread,
Oct 7, 2012, 10:22:37 PM10/7/12
to open...@googlegroups.com
Hello!

2012/10/7 Lance <lance...@gmail.com>:


> 这里有一个之前我就注意到过,后来忘掉的 lua-resty-string,前两天就为了实现 random strong
> 费了半天力气,今天看到这里已经有了。
>

呵呵

> 在它的页面 https://github.com/agentzh/lua-resty-string
> 没有使用文档,只有一些例子,想看有什么功能还得去翻源码,或者从例子里猜。
>

欢迎贡献文档补丁 :)

> 另外 lua-resty-* 系列,能否有一个总的文档,甚至 openresty 发行包的总体功能说明文档,指导用户去哪里找相关的功能呢?
>

欢迎贡献 :D

> 对了,还有两个我最近一直在纠结的功能,类似 php 的 explode 和
> str_replace,基于纯字符串而不是正则表达式的字符串切分和替换,这个在实际使用中我觉得比正则的更加常用。我自己做了一些实现(前两天那些邮件大多与此有关),但总感觉性能不太满意,你看看是否可能扩展在这个包里面呢?
>

这两个可以有 :) 欢迎贡献补丁 :)

Best regards,
-agentzh

Lance

unread,
Oct 7, 2012, 10:25:48 PM10/7/12
to open...@googlegroups.com
ok 那先来一个 explode,功能接口与php定义完全一样

local strfind = string.find
local strsub = string.sub
local strlen = string.len

function explode(sep, str, limit)
    if not sep or sep == "" then return false end
    if not str then return false end
    limit = limit or 0
    if limit < 0 then return {} end

    local r = {}
    local n, init = 0, 1

    while true do
        local s,e = strfind(str, sep, init, true)
        if not s then break end
        r[#r+1] = strsub(str, init, s - 1)
        init = e + 1
        n = n + 1
        if n == limit - 1 then break end
    end

    if init <= strlen(str) then
        r[#r+1] = strsub(str, init)
    else
        r[#r+1] = ""
    end

    return r, n+1
end

Lance


2012/10/8 agentzh <age...@gmail.com>

Best regards,
-agentzh

agentzh

unread,
Oct 7, 2012, 10:29:37 PM10/7/12
to open...@googlegroups.com
Hello!

2012/10/7 Lance <lance...@gmail.com>:
> ok 那先来一个 explode,功能接口与php定义完全一样
>

多谢你提供的实现。不过,你能否以 github pull request 的形式提供补丁呢?同时再提供一些相应的测试用例?

多谢,多谢!

Best regards,
-agentzh

Lance

unread,
Oct 7, 2012, 10:33:55 PM10/7/12
to open...@googlegroups.com
实话实说,我不太会用git提交代码,我可以试试

另外测试用例是写个 .t 吗?没看太明白

Lance


2012/10/8 agentzh <age...@gmail.com>

Best regards,
-agentzh

lhmwzy

unread,
Oct 7, 2012, 10:34:49 PM10/7/12
to open...@googlegroups.com
很好,继续

agentzh

unread,
Oct 7, 2012, 10:46:24 PM10/7/12
to open...@googlegroups.com
Hello!

2012/10/7 Lance <lance...@gmail.com>:
> 实话实说,我不太会用git提交代码,我可以试试
>

多谢! :)

> 另外测试用例是写个 .t 吗?没看太明白
>

.t 是测试文件。我们的测试集都是 Test::Nginx 库驱动的:

http://search.cpan.org/perldoc?Test%3A%3ANginx
http://search.cpan.org/perldoc?Test%3A%3ANginx%3A%3ASocket

如果你有任何问题,也欢迎在邮件列表中交流 :)

多谢!

Best regards,
-agentzh

郭勇

unread,
Oct 8, 2012, 1:52:07 AM10/8/12
to open...@googlegroups.com
内部的location里用proxy_pass访问外部uri是否可行?

在 2012年10月6日星期六UTC+8下午7时33分48秒,kobeng写道:
Message has been deleted

Lance

unread,
Oct 8, 2012, 3:10:59 AM10/8/12
to open...@googlegroups.com
https://github.com/lancelijade/lua-resty-string
弄好了一个,pull request也提交了,.t 按照你原来的文件仿写了一个,不知道实际怎么测,麻烦有时间看一下

Lance


2012/10/8 agentzh <age...@gmail.com>

多谢!

Best regards,
-agentzh

agentzh

unread,
Oct 8, 2012, 1:42:31 PM10/8/12
to open...@googlegroups.com
Hello!

2012/10/7 郭勇 <wolf...@gmail.com>:
> 内部的location里用proxy_pass访问外部uri是否可行?
>

internal location 可以使用 proxy_pass 访问外部 URI,只是 internal location
本身不能直接从外部通过 HTTP 协议被访问到而已。

Best regards,
-agentzh

agentzh

unread,
Oct 8, 2012, 2:53:46 PM10/8/12
to open...@googlegroups.com
Hello!

2012/10/8 Lance <lance...@gmail.com>:


> https://github.com/lancelijade/lua-resty-string
> 弄好了一个,pull request也提交了,.t 按照你原来的文件仿写了一个,不知道实际怎么测,麻烦有时间看一下
>

多谢!我后面找时间看一下 :)

我这会儿正在准备新的 ngx_openresty 稳定版 1.2.3.8 的发布 :) 然后我们就可以把 ngx_lua 模块的
"thread" 分支合回 "master" 啦 :D

Thanks!
-agentzh

Reply all
Reply to author
Forward
0 new messages